简体   繁体   English

nginx:Docker 容器无法启动

[英]nginx: Docker container fails to start

In an attempt to Dockerize an application in four containers, the Nginx container is failing with an error.尝试在四个容器中 Dockerize 应用程序时,Nginx 容器失败并出现错误。 Specifically when I've run docker-compose up it displays:特别是当我运行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

The docker-compose.yml and the nginx configuration and [ETA] the nginx container's Dockerfile.dev are included below.下面docker-compose.yml和 nginx 配置以及 [ETA] nginx 容器的Dockerfile.dev Things I've tried:我尝试过的事情:

  • In docker-compose.yml , setting the nginx container todocker-compose.yml ,将 nginx 容器设置为
depends_on: 
  - client
  • In default.conf , adding resolver 127.0.0.11;default.conf ,添加resolver 127.0.0.11; in the location / section of the server block在服务器块的location /部分

I'm somewhat unfamiliar with nginx and Docker.我对 nginx 和 Docker 有点陌生。 So I'd appreciate any help or insights.所以我很感激任何帮助或见解。


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 ETA nginx-glen/Dockerfile.dev

FROM nginx
COPY ./default.conf /etc/nginx/conf.d/default.conf

The answer lies in the webpack development server, which needs to be instructed to be flexible about the host in the following way:答案在于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: ''
  }

I'll also point out that the nginx container's [emerg] messages in the Docker logs do not seem to prevent the application from running.我还要指出 Docker 日志中 nginx 容器的[emerg]消息似乎不会阻止应用程序运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM