docker-compose为同一图像创建多个实例 [英] docker-compose creating multiple instances for the same image
问题描述
我需要为同一张图片启动多个容器。如果我按如下所示创建我的撰写文件,则可以正常工作。
I need to start multiple containers for the same image. If i create my compose file as shown below, it works fine.
version: '2'
services:
app01:
image: app
app02:
image: app
app03:
image: app
app04:
image: app
app05:
image: app
有没有一种简单的方法可以让我提及撰写实例的数量复制和粘贴多次?
Is there any easy way for me to mention the number of instances for the compose instead of copy and pasting multiple times?
推荐答案
更新后的答案(2017年10月)
Updated answer (Oct 2017)
正如其他人提到的那样,docker API已更改。我正在更新我的答案,因为它是大多数人可能会看的一个。
As others mentioned, the docker API has changed. I'm updating my answer since it's the one most people will probably look at.
docker-compose up -d --scale app = 5
不幸的是,我们目前无法在docker-compose.yml文件中指定此版本(从3.5版开始)。
Unfortunately, we cannot specify this in a docker-compose.yml file currently (as of version 3.5).
详细信息:
他们确实为docker-compose 2.2和2.3版本引入了 scale
选项,但为3.0版。另外,要使用2.2或2.3版本,您需要下载旧版本的docker-compose工具。当前版本不支持2.2或2.3(但是支持2.0或2.1)。
还有一个新的 deploy
部分,其中有副本:5
,但这仅适用于群集模式。
Details:
They did introduce the scale
option for version 2.2 and 2.3 of docker-compose but removed it for version 3.0. Also, to use version 2.2 or 2.3 you would need to download an older version of the docker-compose tool. The current version does not support 2.2 or 2.3 (it does support 2.0 or 2.1 however).
There is also a new deploy
section with replicas: 5
but it's only for swarm mode.
---旧答案-------------------------------- ------
--- Old Answer --------------------------------------
docker-compose scale app = 5
请参见 https://docs.docker.com/compose/reference/scale /
然后,您只需要此docker-compose文件
Then you only need this docker-compose file
version: '2'
services:
app:
image: app
这篇关于docker-compose为同一图像创建多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!