我有一个简单的dockerized Django gunicorn,nginx和postgress项目(每个都是服务)。
当我使用docker-compose up运行它时,一切正常:
maximd@ubuntu ~/PycharmProjects/MyQ (master) $ docker-compose ps
Name Command State Ports
-------------------------------------------------------------------------------
myq_database1_1 docker-entrypoint.sh postgres Up 5432/tcp
myq_djangoapp_1 /bin/sh -c gunicorn --bind ... Up 8000/tcp
myq_nginx_1 nginx -g daemon off; Up 0.0.0.0:8000->80/tcp
但是,当我使用pycharm调试器午餐时,它不会运行nginx。
我怀疑由于djangoapp依赖于我的docker-compose.yml文件中的数据库服务,因此只会创建它们两者,但不会运行nginx。
在用调试器pycharm运行它之后,我会看到以下内容:
maximd@ubuntu ~/PycharmProjects/MyQ (master) $ docker-compose ps
Name Command State Ports
----------------------------------------------------------------------------------------------
myq_database1_1 docker-entrypoint.sh postgres Up 5432/tcp
myq_djangoapp_1 python -u /opt/.pycharm_he ... Up 0.0.0.0:55488->55488/tcp, 8000/tcp
myq_nginx_1 nginx -g daemon off; Exit 0
所以,我的问题是:是否有办法使nginx也成为djangoapp的依赖项?有没有办法让pycharm运行所有服务,而不仅仅是我要调试的服务?
这是我的docker-compose.yml文件:
version: '3'
services:
djangoapp:
build: .
volumes:
- .:/services/djangoapp
- static_volume:/services/djangoapp/static
- media_volume:/services/djangoapp/media
networks:
- nginx_network
- database1_network
depends_on:
- database1
nginx:
image: nginx:1.13
ports:
- 8000:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/services/djangoapp/static
- media_volume:/services/djangoapp/media
depends_on:
- djangoapp
networks:
- nginx_network
database1: # <-- IMPORTANT: same name as in DATABASES setting, otherwise Django won't find the database!
image: postgres:10
env_file:
- config/db/database1_env
networks:
- database1_network
volumes:
- database1_volume:/var/lib/postgresql/data
networks:
nginx_network:
driver: bridge
database1_network:
driver: bridge
volumes:
database1_volume:
static_volume:
media_volume:
答案 0 :(得分:1)
最终解决了该问题,将docker-compose.yml更改为:
version: '3'
services:
djangoapp:
build: .
restart: always
volumes:
- .:/services/djangoapp
- static_volume:/services/djangoapp/static
- media_volume:/services/djangoapp/media
networks:
- nginx_network
- database1_network
depends_on:
- database1
- nginx
nginx:
image: nginx:1.13
restart: always
ports:
- 8000:80
volumes:
- ./config/nginx/conf.d:/etc/nginx/conf.d
- static_volume:/services/djangoapp/static
- media_volume:/services/djangoapp/media
networks:
- nginx_network
database1: # <-- IMPORTANT: same name as in DATABASES setting, otherwise Django won't find the database!
image: postgres:10
env_file:
- config/db/database1_env
networks:
- database1_network
volumes:
- database1_volume:/var/lib/postgresql/data
networks:
nginx_network:
driver: bridge
database1_network:
driver: bridge
volumes:
database1_volume:
static_volume:
media_volume:
基本上使djangoapp依赖于nginx,并添加重新启动:始终添加到nginx和djangoapp。
也在“运行/调试配置”窗口中:
主机为:0.0.0.0
工作目录:/ services / djangoapp(类似于djangoapp中的目录)
路径映射:/ home / maximd / PycharmProjects / MyQ = / services / djangoapp
答案 1 :(得分:0)
我怀疑您的nginx容器本身就掉了,只需检查docker logs myq_nginx_1