简体   繁体   English

Docker compose删除了另一个容器

[英]Docker compose removes another container

I have a project with one basic docker-compose.yml file and then 2 another file - each for one environment docker-compose.dev.yml and docker-compose.prod.yml . 我有一个项目,其中包含一个基本docker-compose.yml文件,然后包含2个其他文件-每个文件均用于一个环境docker-compose.dev.ymldocker-compose.prod.yml

docker-compose.yml 泊坞窗,compose.yml

version: "2"

services:
    app:
        build: 
            context: .
        depends_on:
            - redis
            - selenium
        networks:
            - richy

    redis:
        image: redis:3.2
        container_name: redis
        networks:
            - richy

    selenium:
        image: selenium/standalone-chrome
        container_name: selenium
        networks:
            - richy

networks:
    richy:
        driver: bridge

docker-compose.dev.yml 泊坞窗,compose.dev.yml

version: "2"

services:
    app:
        build: 
            args:
                env: dev
        image: richy_image:dev-latest
        container_name: richy-dev
        volumes:
            - .:/var/www/richy
        ports:
            - 9000:80
        environment: 
            - ENV=dev

docker-compose.prod.yml 泊坞窗,compose.prod.yml

version: "2"

services:
    app:
        build: 
            args:
                env: prod
        image: richy_image:prod-latest
        container_name: richy-prod
        volumes:
            - /home/grafa/workspace/prichy/richy/db.sqlite3:/var/www/richy/richy/db.sqlite3
        ports:
            - 9001:80
        environment: 
            - ENV=prod

I run my dev/prod environments like docker-compose -f docker-compose.yml -f docker-compose.(dev|prod).yml up 我运行诸如docker-compose -f docker-compose.yml -f docker-compose.(dev|prod).yml up类的开发/产品环境docker-compose -f docker-compose.yml -f docker-compose.(dev|prod).yml up

The thing is I cannot run there both containers side by side despite I was able to do it like a month ago and few changes ago. 问题是,尽管我能够像一个月前那样做并且很少改动,但我不能同时在两个容器上同时运行。 Everytime I have running for example dev environment and I spawn docker-compose for prod environment docker spits out this: 每次我运行例如dev环境时,我就生成docker-compose到prod环境中,docker会吐出以下内容:

redis is up-to-date
selenium is up-to-date
Recreating richy-dev

which is strange because why it wants to recreate the richy-dev container when I'm starting the richy-prod. 这很奇怪,因为为什么当我启动richy-prod时为什么要重新创建richy-dev容器。

Maybe there is a conflict in my config files. 也许我的配置文件中有冲突。 Can you guys please help me? 你们能帮我吗?

Thank you. 谢谢。

Basically to differentiate between container names of two environments, you will need to define project name explicitly. 基本上是要区分两种环境的容器名称,您将需要显式定义项目名称。 otherwise it takes the name based on the folder name. 否则,它将根据文件夹名称获取名称。

you can use -p or the COMPOSE_PROJECT_NAME environment variable for that. 您可以为此使用-p或COMPOSE_PROJECT_NAME环境变量。

taken from: https://github.com/docker/compose/issues/2982#issuecomment-186835033 摘自: https : //github.com/docker/compose/issues/2982#issuecomment-186835033

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM