Kit*_*son 58 docker docker-compose docker-container
我需要为同一个图像启动多个容器.如果我创建我的撰写文件,如下所示,它工作正常.
version: '2'
services:
app01:
image: app
app02:
image: app
app03:
image: app
app04:
image: app
app05:
image: app
Run Code Online (Sandbox Code Playgroud)
有没有简单的方法让我提到组合的实例数而不是多次复制和粘贴?
Ber*_*ard 67
更新的答案(2017年10月)
正如其他人提到的,docker API已经改变.我正在更新我的答案,因为它是大多数人可能会看到的.
docker-compose up -d --scale app=5
不幸的是,我们目前无法在docker-compose.yml文件中指定它(从版本3.5开始).
详细信息:
他们确实引入了scaledocker-compose版本2.2和2.3 的选项,但是将其删除为版本3.0.此外,要使用2.2或2.3版,您需要下载旧版本的docker-compose工具.当前版本不支持2.2或2.3(但它支持2.0或2.1).还有一个新的deploy部分,replicas: 5但它只适用于群模式.
---旧答案--------------------------------
docker-compose scale app=5
请参阅https://docs.docker.com/compose/reference/scale/
那么你只需要这个docker-compose文件
version: '2'
services:
app:
image: app
Run Code Online (Sandbox Code Playgroud)
fss*_*lva 27
该scale命令现已弃用,您应该使用该命令up.
docker-compose up --scale app=2
Run Code Online (Sandbox Code Playgroud)
https://docs.docker.com/compose/reference/up中的更多详细信息
小智 15
您可以replica按照https://docs.docker.com/compose/compose-file/#replicas中的说明进行操作
version: '3'
services:
worker:
image: dockersamples/examplevotingapp_worker
networks:
- frontend
- backend
deploy:
mode: replicated
replicas: 6
Run Code Online (Sandbox Code Playgroud)
Ale*_*122 13
You can do this:
version: "3.4"
services:
service1: &service_1
image: app
service2:
<<: *service_1
service3:
<<: *service_1
Run Code Online (Sandbox Code Playgroud)
For more information on <<, see What is the << (double left arrow) syntax in YAML called, and where's it specified?.
| 归档时间: |
|
| 查看次数: |
53614 次 |
| 最近记录: |