即使测试成功,nginx容器也会以代码0退出

时间:2019-07-21 14:20:16

标签: docker nginx deployment docker-compose

我想使用nginx将端口从我的ec2服务器外部映射到我在docker-compose.yml中定义为

的“网站”服务
website:
    build: .
    command: >
      gunicorn -c "python:config.gunicorn" "project.app:create_app()"
    environment:
      PYTHONUNBUFFERED: 'true'
    volumes:
      - '.:/project'
    ports:
      - '5000:5000'
    expose:
      - "5000"
    restart: always

和nginx服务构建为

nginx:
    build:
      dockerfile: Dockerfile
      context: ./nginx
    ports:
      - '3000:80'
      - '443:443'

    command: nginx -t -c /etc/nginx/default.conf

Dockerfile

FROM nginx:1.17.1


COPY ./default.conf /etc/nginx/default.conf

CMD ["nginx", "-g", "daemon off;"]

test命令返回成功,然后意外失败。我怎么解决这个问题?

nginx_1    | nginx: the configuration file /etc/nginx/default.conf syntax is ok
nginx_1    | nginx: configuration file /etc/nginx/default.conf test is successful
redis_1    | 1:C 21 Jul 2019 13:59:37.511 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1    | 1:C 21 Jul 2019 13:59:37.512 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1    | 1:C 21 Jul 2019 13:59:37.512 # Configuration loaded
collection-pro_nginx_1 exited with code 0

我认为问题来自default.conf文件

default.conf文件如下

events {
  worker_connections 2048;
  multi_accept on;
  use epoll;
}

http{

  upstream website {
    server website:5000;
  }
  server {
    listen 80;

    location / {
       proxy_pass http://website;
    }
 }

}

将服务名称nginx更改为nginx-container,现在错误终于来了,nginx: [emerg] host not found in upstream "website:5000" in /etc/nginx/default.conf:11 接近胜利

0 个答案:

没有答案