How can I run the same docker-compose.yml several times on the same docker daemon with different names?

My position. Attempts to run docker structure in one box several times. This is my docker-compose.yml :

version: '3' services: code: image: organization:java-maven links: - mysql:mysql volumes: - "${PWD}:/home/ubuntu/src" mysql: image: organization:mysql 

Doing this twice with docker-compose run code mvn clean test creates two code containers and one mysql container.

Now I want one code be associated with one mysql and another code associated with another mysql .

How to do it? It is assumed that it runs on subordinate jenkins, and maven executions cannot use mysql.

I tried unsuccessfully with the "-e KEY = VALUE" option for docker-compose run along with container_name in the docker-compose run file.

Not sure how to approach this, please help, thanks.

+17
docker docker-compose
source share
1 answer

So I focused too much on using directives to manually change container names. The solution was much simpler.

docker-compose -p anything run code mvn clean test

docker-compose -p anything_else run code mvn clean test

So this is the solution for the project name. Docker compose will use the value specified by the -p parameter as a prefix when creating container names. This means that there is no collision.

Very handy!

For more information: documentation around the project name option

+17
source share

All Articles