[英]nginx: Docker container fails to start
嘗試在四個容器中 Dockerize 應用程序時,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;
}
}
ETA 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: ''
}
我還要指出 Docker 日志中 nginx 容器的[emerg]
消息似乎不會阻止應用程序運行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.