个具有不同名称的docker守护程序上多次运行同一个docker

个具有不同名称的docker守护程序上多次运行同一个docker

本文介绍了如何在同一个具有不同名称的docker守护程序上多次运行同一个docker-compose.yml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的情况。尝试在同一盒子上多次运行docker-compose结构。这是我的 docker-compose.yml

 版本:'3'
服务:
代码:
图像:组织:java-maven
链接:
-mysql:mysql
数量:
- $ {PWD}:/首页/ ubuntu / src
mysql:
图片:organization:mysql

使用 docker-compose运行代码mvn clean test 运行两次,将创建两个 code 容器和一个 mysql



现在,我想将一个代码链接到一个 mysql 另一个 代码链接到另一个 mysql



我该怎么做?



我为<$>尝试使用 -e KEY = VALUE选项非常失败。 c $ c> docker-compose run 和docker compose文件中的 container_name



不确定如何解决此问题,请帮忙,谢谢。

解决方案

因此,我过多地关注于使用指令来手动更改容器名称。该解决方案要容易得多。 b
$ b

docker-compose -p any_else运行代码mvn clean test



,这是项目名称解决方案。创建容器名称时,Docker compose将使用选项 -p 给出的值作为前缀。



非常方便!



更多信息:


My situation. Trying to run a docker-compose structure several times on the same box. 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

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

Now, I want one code to be linked to one mysql, and another code linked to another mysql.

How do I accomplish this? This is supposed to run on jenkins slaves and the maven executions cannot share mysql.

I've miserably failed trying with the "-e KEY=VALUE" option for docker-compose run together with container_namein the docker compose file.

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. That means no collision.

Very handy!

For more reading: documentation around project-name option

这篇关于如何在同一个具有不同名称的docker守护程序上多次运行同一个docker-compose.yml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:33