And*_*bbs 14 docker docker-compose
如果我有(简化),则以下docker-compose.yml:
parent:
image: parent
links:
- child
child:
image: child
Run Code Online (Sandbox Code Playgroud)
我可以构建一个不会创建或启动图像的docker-compose.override.yml文件吗?child
一个不受欢迎的(对我来说)解决方案是反转文件,这样默认的yml文件只会创建parent,而覆盖会创建两者.
但是,我希望主配置文件包含最常见的使用方案.
为了保护原始海报:我完全明白你为什么要这样做.Docker-compose方式似乎总是"将您的变体放在覆盖文件中",但为了在大型开发团队中保持简单,我喜欢:
这是我在覆盖文件中的做法:
# Disable database containers
postgres:
image: alpine:latest
command: "true"
entrypoint: "true"
mysql:
image: alpine:latest
command: "true"
entrypoint: "true"
Run Code Online (Sandbox Code Playgroud)
结果是,所有容器都是由"docker-compose up"启动的,但那些我已经覆盖的容器会立即死掉.
如果你想要一个比阿尔卑斯山更轻的重量容器,试试tianon/true.
我真的很喜欢Ryan的解决方案。但可以改进:
# disable services
fluentd:
image: hello-world
command: hello
restart: no
elasticsearch:
image: hello-world
command: hello
restart: no
Run Code Online (Sandbox Code Playgroud)
我相信hello-world是最小的映像(大小:〜1Kb),另一方面,alpineLinux 的大小是〜6Mb
对于 compose < 1.28 的版本,2021 年 1 月
如果您在覆盖文件中禁用多个服务(如Ryan 的回答),您可能会发现不要重复自己使用扩展字段和yaml锚点(本质上是“反向引用” yaml)很有用。
如:
# Your version
version: "2.4"
# `&anchor-name` defines the anchor (Here it is a map/dict)
# `*anchor-name` references the anchor
# `<<: *anchor-name` merges (`<<:`) the keys of `*anchor-name` with the current map
x-disabled-service: &disabled
image: "tianon/true"
command: "true"
entrypoint: "true"
services:
elasticsearch:
<<: *disabled
fluentdb:
<<: *disabled
Run Code Online (Sandbox Code Playgroud)
这将tianon/true按照Ryan 评论中的建议用作非常小的图像。
结果在功能上与 Ryan 或Roman 的答案相同,但不那么冗长。
对于撰写版本 >= 1.28
另外,根据mcarson的回答类似的问题,SO作为撰写1.28,2021年1月,存在一个新的撰写领域profiles,它可以让你组在一起的容器,可以在使用命令行选项进行切换--profile。
https://docs.docker.com/compose/profiles/
| 归档时间: |
|
| 查看次数: |
3883 次 |
| 最近记录: |