我尝试运行Docker容器:nginx,python和psql。我的nginx容器取决于python容器。但是因为gunicorn不会发送退出信号,所以nginx容器无法运行。
我试图更改工作程序类型:gevent和eventlet,但仍然相同。
# docker-compose.yml
version: '2'
services:
nginx:
image: nginx:latest
container_name: ng02
ports:
- "8002:8002"
volumes:
- ./src:/src
- ./config/nginx:/etc/nginx/conf.d
- /static:/static
- ./src/media:/media
depends_on:
- web
web:
build: .
container_name: dg02
command: bash -c "python manage.py collectstatic --no-input && python manage.py makemigrations && python manage.py migrate && gunicorn --timeout 300 --workers=3 myapp.wsgi -b 0.0.0.0:8002 -k eventlet"
depends_on:
- db
volumes:
- ./src:/src
- /static:/static
- /media:/media
expose:
- "8002"
db:
image: postgres:latest
container_name: ps02
# Dockerfile
FROM python:3.6
ENV PYTHONUNBUFFERED 1
RUN mkdir /config
ADD /config/requirements.pip /config/
RUN pip install -r /config/requirements.pip
RUN mkdir /src;
WORKDIR /src
docker-compose up
的输出如下:
dg02 | [2019-09-10 07:29:23 +0000] [1] [INFO] Starting gunicorn 19.9.0
dg02 | [2019-09-10 07:29:23 +0000] [1] [INFO] Listening at: http://0.0.0.0:8002 (1)
dg02 | [2019-09-10 07:29:23 +0000] [1] [INFO] Using worker: eventlet
dg02 | [2019-09-10 07:29:23 +0000] [14] [INFO] Booting worker with pid: 14
dg02 | [2019-09-10 07:29:24 +0000] [15] [INFO] Booting worker with pid: 15
dg02 | [2019-09-10 07:29:24 +0000] [16] [INFO] Booting worker with pid: 16
这就是问题所在。 dg02
不存在,因此ng02
无法开始。我该如何克服这个问题?