3
votes

I am having 3 compose file overrides, for dev, QA, staging environments. I have one server and there I have to host/run containers for QA and Staging environments (completely separately !!. separate containers, network, and volumes).

In each compose file overrides, I am having different volume names, network names, image names, container names, all controlled by environment-specific .env files.

When I run docker-compose -f "docker-compose.yml" -f "docker-compose.qa.yml" up -d, it creates QA environment images and runs containers having name QA in it.

When I run docker-compose -f "docker-compose.yml" -f "docker-compose.staging.yml" up -d, it creates Staging environment images and runs containers having name Staging in it.

but I am not able to run both simultaneously. Port bindings are also controlled by .env files and are different for each environment.

(I am able to specify the .env file I have to use during docker-compose up command)

services:
   service1:
     networks:
       - dev
     volumes:
       - "vol_service1:/some/path/to/container"
   service2:
     networks:
       - dev
     volumes:
       - "vol_service2:/some/path/to/container"
   service3:
     networks:
       - dev
     volumes:
       - "vol_service3:/some/path/to/container"
   service4:
     networks:
       - dev
     volumes:
       - "vol_service4:/some/path/to/container"

networks:
  dev:
    driver:bridge

volumes:
 vol_service1:
 vol_service2:
 vol_service3:
 vol_service4:

I am using Docker for Windows, following are the details:

Client: Docker Engine - Community
 Version:           18.09.2
 API version:       1.39
 Go version:        go1.10.8
 Git commit:        6247962
 Built:             Sun Feb 10 04:12:31 2019
 OS/Arch:           windows/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.2
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       6247962
  Built:            Sun Feb 10 04:13:06 2019
  OS/Arch:          linux/amd64
  Experimental:     false
1
What specifically doesn't work? Can you edit the question to have a docker-compose.yml file that launches one container, and matching dev and prod environment files, but you can't launch both together? - David Maze
Yes, I cannot run 2 environments together on same machine. - Deepanshu

1 Answers

3
votes

That was really silly on my part. I missed out an important point in the documentation on docker-compose. You need to specify COMPOSE_PROJECT_NAME environment variable, if not specified then it will pick up the folder name where your compose file resides. Just name this environment variable differently for your environment and you are good to go.