【问题标题】:Nginx do not start with docker-compose run commandNginx 不以 docker-compose 运行命令启动
【发布时间】:2021-01-13 10:06:44
【问题描述】:

我正在对接我现有的应用程序。但是有一个奇怪的问题。当我开始我的应用程序时

docker-compose up

docker-compose 中的每个服务都可以成功运行,没有任何问题。但是有些服务我有时不想运行(celery、celerybeat 等)。为此我运行

docker-compose run nginx

上述命令应该运行 docker-compose.yml 配置的 nginx、web、db 服务,但它只运行 web 和 db 而不是 nginx。

这是我的 yml 文件

docker-compose.yml

version: '3'

services:
    db:
        image: postgres:12
        env_file: .env
        environment:
            - POSTGRES_DB=${DB_NAME}
            - POSTGRES_USER=${DB_USER}
            - POSTGRES_PASSWORD=${DB_PASSWORD}
        ports:
            - "5431:5432"
        volumes:
            - dbdata:/var/lib/postgresql/data
    nginx:
        image: nginx:1.14
        ports:
            - "443:443"
            - "80:80"
        volumes:
            - ./config/nginx/:/etc/nginx/conf.d
            - ./MyAPP/static:/var/www/MyAPP.me/static/
        depends_on:
            - web
    web:
        restart: always
        build: ./MyAPP
        command:  bash -c "
                    python manage.py collectstatic --noinput 
                    && python manage.py makemigrations
                    && python manage.py migrate
                    && gunicorn --certfile=/etc/certs/localhost.crt --keyfile=/etc/certs    /localhost.key MyAPP.wsgi:application --bind 0.0.0.0:443 --reload"
        expose:
            - "443"
        depends_on:
            - db
        env_file:
            - .env
        volumes:
            - ./MyAPP:/opt/MyAPP
            - ./config/nginx/certs/:/etc/certs
            - ./MyAPP/static:/var/www/MyAPP.me/static/

    broker:
        image: redis:alpine
        expose: 
            - "6379"
    
    celery:
        build: ./MyAPP
        command: celery -A MyAPP worker -l info
        env_file:
            - .env
        volumes:
            - ./MyAPP:/opt/MyAPP
        depends_on:
            - broker
            - db

    celery-beat:
        build: ./MyAPP
        command: celery -A MyAPP beat -l info
        env_file:
            - .env
        volumes:
            - ./MyAPP:/opt/MyAPP
        depends_on:
            - broker
            - db
    comment-classifier:
        image: codait/max-toxic-comment-classifier

volumes:
    dbdata:

【问题讨论】:

    标签: docker nginx server docker-compose dockerfile


    【解决方案1】:

    TL;博士:docker-compose up nginx

    docker-compose updocker-compose run 之间存在明显区别。第一个构建、(重新)创建、启动并附加到服务容器。第二个对服务运行一次性命令。当您执行docker-compose run 时,它会启动 db 和 web,因为 nginx 依赖于它们,然后它在 nginx 上运行单个命令并退出。所以你必须使用docker-compose up nginx 才能得到你想要的。

    【讨论】:

    • 正是我想要的。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    相关资源
    最近更新 更多