理想的情况是每个容器只有一个流程,但在以下几个方面有很强的亲和力。Flask+Uwsgi 和 Nginx.
目前我们把它们放在一起运行,但是我们应该重构吗?
是的,重构是个好主意。尽量让服务成为短暂的,并且只运行一个主进程。所以,最后,你需要有这样的东西。
version: '3.4'
services:
web:
build:
dockerfile: Dockerfile
context: .
ports:
- 8000:8000
volumes:
- .:/app/
env_file:
- common.env
nginx:
restart: always
image: nginx:1.18-alpine
ports:
- 80:80
- 443:443
volumes:
- ./deployment/nginx.conf:/etc/nginx/conf.d/default.conf
- ./deployment/config.conf:/etc/nginx/nginx.conf
command: "/bin/sh -c 'while :; do sleep 6h & wait $${!}; nginx -s reload; done & nginx -g \"daemon off;\";'"
depends_on:
- web
它的设计是为了在一个容器中只有一个主进程 如果你的应用失败了,容器就会瘫痪。