docker - nginx:Docker 容器无法启动
问题描述
在尝试将应用程序 Docker 化到四个容器中时,Nginx 容器因错误而失败。特别是当我运行docker-compose up
它时显示:
nginx_1 | 2019/12/25 23:00:50 [emerg] 1#1: host not found in upstream "client:8080" in /etc/nginx/conf.d/default.conf:2
nginx_1 | nginx: [emerg] host not found in upstream "client:8080" in /etc/nginx/conf.d/default.conf:2
下面docker-compose.yml
包括 nginx 配置和 [ETA] nginx 容器Dockerfile.dev
。我尝试过的事情:
- 中
docker-compose.yml
,将 nginx 容器设置为
depends_on:
- client
- 在
default.conf
,添加resolver 127.0.0.11;
在location /
服务器块的部分
我对nginx和Docker有些陌生。因此,我将不胜感激任何帮助或见解。
docker-compose.yml
version: '3'
services:
db:
image: 'postgres:latest'
nginx:
build:
dockerfile: Dockerfile.dev
context: ../nginx-glen
restart: always
ports:
- '3050:80'
api:
build:
dockerfile: Dockerfile.dev
context: ../cornish-glen
volumes:
- /app/node_modules
- ../cornish-glen:/app
depends_on:
- db
environment:
- PGUSER=postgres
- PGHOST=postgres
- PGDATABASE=turnip_glen
- PGPASSWORD=********
- PGPORT=5432
client:
build:
dockerfile: Dockerfile.dev
context: .
depends_on:
- api
volumes:
- /app/node_modules
- .:/app
environment:
- GRAPHQL_ORIGIN=http://api:3099
default.conf
upstream client {
server client:8080;
}
upstream api {
server api:3099;
}
server {
listen 80;
location / {
proxy_pass http://client;
}
location /sockjs-node {
proxy_pass http://client;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
location /graphql {
proxy_pass http://api;
}
}
预计到达时间 nginx-glen/Dockerfile.dev
FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf
解决方案
答案就在 webpack 开发服务器上,需要通过以下方式来指示它对主机的灵活处理:
// Only showing the devServer object here:
devServer: {
// These two lines are the relevant ones:
// ---
host: '0.0.0.0',
disableHostCheck: true, // TODO: insecure, but probably fine for dev environment
// ---
contentBase: "./public",
index: ''
}
我还要指出,[emerg]
Docker 日志中的 nginx 容器消息似乎并没有阻止应用程序运行。
推荐阅读
- android - E/FirebaseInstanceId:令牌检索失败:INVALID_SENDER
- android - 仅打开一次底部工作表对话框
- assembly - 怎么 ”!” Armv6-M架构编码中“LDM R1!{R2}”指令的一部分?
- python - 根据它们在矩阵中的位置将 2D numpy 数组中零值的坐标分组到列表中
- c# - 我想删除自己的播放器对象,但我不能使用 Destroy | PUN2
- windows - 在 CMD 中反向输出
- c# - 如何以 xamarin 形式在观察集合中搜索观察集合?
- sql-server - 使用 CTE 遍历闭包表的问题
- php - 检查phpmysql数据库中是否已存在行的代码
- python - 返回 pandas 计数函数的数值