运行多个docker compose [英] Run multiple docker compose

查看:213
本文介绍了运行多个docker compose的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用在3个不同的docker上运行的应用程序:

I am using an application which run on 3 different dockers:

  • 第一个是可通过REST API调用的服务器HTTP
  • 第二个是Rabbitmq
  • 第三个是工人

使用docker-compose up

真的很简单:)

我想使其具有可伸缩性,并且独立于其他应用程序运行整个整个应用程序的多个实例(3个docker映像),然后放置一个像haproxy这样的负载均衡器,它将重定向到其中一个应用程序.

I would like to make it scalable and run multiple instances of this entire application (the 3 docker images) independently of the others, and then put a load balancer like haproxy which will redirect to one of the applications.

我看到我可以使用docker-compose up --scale blablabla,但是这样做的问题是我可以缩放容器,但是我真的想保持不同的应用程序"独立.

I saw that I can use docker-compose up --scale blablabla however the problem with this is that I can scale containers, but I really want to keep the different "application" independent.

例如,如果我想要3个版本的应用程序,则将有9个dockers映像等.

For example if I want 3 version of the app I will have 9 dockers images etc.

我看到我们可以使用--privilege在docker内部运行docker(允许我创建一个内部有3个docker的docker),但是我在Stack Overflow上读到它不是一个合适的解决方案.

I saw that we can run docker inside docker with --privilege (allowing me to create one docker with the 3 dockers inside) but I read on Stack Overflow that it is not a suitable solution.

您有解决方案吗?或至少要阅读一些文档.

Do you have a solution? Or at least some documents to read.

我听说Kubernetes可能是一个解决方案,但我不确定.我读(在堆栈上)

I heard that Kubernetes could be a solution but I am not sure. I read (on stack)

如果您需要紧密绑定多个容器,则可能需要查看在其"pods"中运行docker的Kubernetes.

If you need multiple containers tightly bound, you may want to look at Kubernetes that runs docker inside their "pods"

推荐答案

听起来您只希望Compose应用程序的3个不同环境或堆栈"彼此独立运行.在这种情况下,可以使用docker-compose--project-name-p选项进行处理.一个例子就是这样:

It sounds like you just want 3 different environments or "stacks" of your Compose application running independently of each other. If this is the case, you can handle this with the --project-name or -p option to docker-compose. An example would be something like this:

  • 启动应用程序版本1:docker-compose -p appv1 up -d
  • 启动应用程序版本2:docker-compose -p appv2 up -d
  • 启动应用程序版本3:docker-compose -p appv3 up -d
  • Launch application version 1: docker-compose -p appv1 up -d
  • Launch application version 2: docker-compose -p appv2 up -d
  • Launch application version 3: docker-compose -p appv3 up -d

这时,您将运行3组不同的容器,这些容器可以相互独立缩放. Docker Compose将在项目名称(通常从文件夹名称推断)之前加上容器名称.您最终将得到容器名称,例如appv1_worker_1appv2_worker_1appv3_worker1.如果仅扩展appv2工作者服务(docker-compose -p appv2 scale worker=2),则将获得额外的appv2_worker_2.

At this point, you would have 3 different sets of containers running that can scale independently of each other. Docker Compose will prepend the project name (which is usually inferred from the folder name) to the container names. You will end up with container names such as appv1_worker_1, appv2_worker_1, appv3_worker1. If you were to scale only appv2 worker service (docker-compose -p appv2 scale worker=2) you would then get an additional appv2_worker_2.

默认情况下,compose总是创建一个默认网络,容器可以在其中与之对话.在这种情况下,您将拥有3个独立的网络(appv1_defaultappv2_defaultappv3_default).

By default, compose always creates a default network that the containers can talk inside of. In this case, you would have 3 independent networks (appv1_default, appv2_default, and appv3_default).

如果下一个要为每个项目名称运行不同的图像,则可以在docker-compose.yml中使用环境变量插值.例如,您可以为服务指定image: ${MYIMAGE},然后执行以下操作:

If you next wanted to run different images for each project name, you could use environment variable interpolation in the docker-compose.yml. For example, you could specify image: ${MYIMAGE} for a service and then do something such as:

  • MYIMAGE=myorg/myapp:v1 docker-compose -p appv1 up -d
  • MYIMAGE=myorg/myapp:v2 docker-compose -p appv2 up -d
  • MYIMAGE=myorg/myapp:v1 docker-compose -p appv1 up -d
  • MYIMAGE=myorg/myapp:v2 docker-compose -p appv2 up -d

希望这对在Docker Compose内实现此想法很有帮助.

Hope this is helpful as an idea to do it inside of Docker Compose.

这篇关于运行多个docker compose的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆