[英]How do I run the same docker-compose.yml several times on same docker daemon with different names?
My situation. 我的情况。 Trying to run a docker-compose structure several times on the same box. 试图在同一个盒子上多次运行一个docker-compose结构。 This is my docker-compose.yml : 这是我的docker-compose.yml :
version: '3'
services:
code:
image: organization:java-maven
links:
- mysql:mysql
volumes:
- "${PWD}:/home/ubuntu/src"
mysql:
image: organization:mysql
Running this twice with docker-compose run code mvn clean test
creates two containers of code
and one container of mysql
. 使用docker-compose run code mvn clean test
运行这两次docker-compose run code mvn clean test
会创建两个code
容器和一个mysql
容器。
Now, I want one code
to be linked to one mysql
, and another code
linked to another mysql
. 现在,我希望一个code
链接到一个mysql
, 另一个 code
链接到另一个 mysql
。
How do I accomplish this? 我该如何做到这一点? This is supposed to run on jenkins slaves and the maven executions cannot share mysql. 这应该是在jenkins奴隶上运行的,并且maven执行不能共享mysql。
I've miserably failed trying with the "-e KEY=VALUE" option for docker-compose run
together with container_name
in the docker compose file. 我docker-compose run
在docker-compose run
compose文件中使用docker-compose run
与container_name
一起docker-compose run
“-e KEY = VALUE”选项。
Not sure how to approach this, please help, thank you. 不知道该如何处理,请帮助,谢谢。
So, I focused too much on using directives to alter container names manually. 因此,我过分关注使用指令手动更改容器名称。 The solution was much easier. 解决方案要容易得多。
docker-compose -p anything run code mvn clean test
docker-compose -p anything_else run code mvn clean test
So, this is the project name solution. 所以,这是项目名称解决方案。 Docker compose will use the value given with the option -p
as a prefix when creating container names. 在创建容器名称时,Docker compose将使用选项-p
作为前缀给出的值。 That means no collision. 这意味着没有碰撞。
Very handy! 非常便利!
For more reading: documentation around project-name option 有关更多阅读:有关项目名称选项的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.