【问题标题】:Should Nginx and Flask run in the same containerNginx 和 Flask 是否应该在同一个容器中运行
【发布时间】:2020-05-29 22:30:33
【问题描述】:

理想的情况是每个容器有一个进程,但是 Flask+uwsgi 和 Nginx 之间有很强的亲和力。

目前我们一起运行它们,但我们应该重构吗?

【问题讨论】:

    标签: docker nginx flask


    【解决方案1】:

    是的,重构是个好主意。尝试使服务短暂并仅在其中运行一个主进程。所以,最后,你需要有这样的东西:

    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
    

    它被设计为在一个容器中只有一个主进程,在这种情况下,如果您的应用程序失败,该容器将关闭。

    【讨论】:

      猜你喜欢
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-15
      • 2018-07-19
      • 2012-03-10
      • 1970-01-01
      相关资源
      最近更新 更多