nginx:Docker容器无法启动

时间:2019-12-27 02:26:47

标签: docker nginx docker-compose

尝试在四个容器中对应用程序进行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;
  }
}

ETA nginx-glen/Dockerfile.dev

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

1 个答案:

答案 0 :(得分:0)

答案就在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]消息似乎并没有阻止应用程序运行。

相关问题