I understand that you can user docker-compose with the scale command to spin up multiple containers. However, they will all have the same configuration used.
Is it possible to launch a container on the same host with different configurations (different .yml
files) on the same host?
Using the following commands:
docker-compose -f dev.yml up -d docker-compose -f qa.yml up -d
only the qa.yml
container will be running, which is not what I want.
-- edit --
Here's what happens when I try running both commands.
$ docker-compose -f compose/dev.yml up -d compose_mydocker_1 is up-to-date $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 905912df6e48 compose_mydocker "/sbin/my_init" 2 days ago Up 2 days 0.0.0.0:1234->80/tcp compose_mydocker_1 $ docker-compose -f compose/qa.yml up -d Recreating compose_mydocker_1... $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3fc912201224 compose_mydocker "/sbin/my_init" 5 seconds ago Up 5 seconds 0.0.0.0:1235->80/tcp compose_mydocker_1
My qa.yml
and dev.yml
look like this:
mydocker: build: .. ports: - "1234:80" #for dev.yml #- "1235:80" for qa.yml environment: - ENVIRONMENT=dev #and vice-versa for qa volumes: - ../assets/images:/var/www/assets
Yes. You can run multiple containers on one server, and it is not restricted to the number of CPUs. Your command creates and starts exactly 1 container that has access to at most 16 CPUs (and in the 2nd example only precisely CPUs 0-15).
If you're expecting it to behave the same way, as when running a single container, it won't happen. If there's no specific reason for using version: '3' you may use version:'2' instead. Or you can let it create its own network, which it does with your current docker-compose file.
🔗 Compose uses the project name to create unique identifiers for all of a project's containers and other resources. To run multiple copies of a project, set a custom project name using the -p command line option or the COMPOSE_PROJECT_NAME environment variable.
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.
What you need to do is change the project name. By default, compose uses a project named based on the current directory. In your case, you want separate environments, so you need different project names.
You can use either docker-compose -p <project_name>
or set COMPOSE_PROJECT_NAME
in the environment.
There is also some discussion about providing a way to persist the project name: https://github.com/docker/compose/issues/745
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With