有什么办法可以禁用docker-compose.yml中的服务 [英] Is there any way to disable a service in docker-compose.yml
问题描述
我遇到了这种情况,我想暂时禁用 docker-compose
文件中的服务。
I find myself in the situation, that I want to disable a service temporarily in a docker-compose
file.
我当然可以将其注释掉,但是有什么选择可以说 enabled:false
吗?
Of course I could comment it out, but is there any option to just say "enabled: false
" ?
推荐答案
您可以简单地重新定义 entrypoint
或 command
以便将上述命令替换为什么都不做( / bin / true
)
You could simply redefine the entrypoint
or command
in order to replace said command with something which does nothing (/bin/true
)
那会使容器立即退出,什么也不做。
That would make the container exit immediately, doing nothing.
shadi 在评论中添加了以下提示:
shadi adds the following tips in the comments:
如果您根本不想构建服务,请重新定义构建密钥以指向
Dockerfile
仅具有:
FROM tianon/true
ENTRYPOINT ["/true"]
5andr0 指出< a href = https://stackoverflow.com/users/86145/5andr0>评论中 顶级部分 x-disabled:
(类似于扩展字段)
5andr0 points out in the comments the top-level section x-disabled:
(an extension field-like)
更方便:将禁用的服务移至顶级部分 x-disabled:
而不是 services:
Far more convenient: moving disabled services to the top-level section
x-disabled:
instead ofservices:
具有 x-
前缀的部分将被解析,但如果未按预期方式使用,则将被忽略扩展字段。
Sections with the x-
prefix will be parsed, but ignored if not used in the intended way as an extension field.
这篇关于有什么办法可以禁用docker-compose.yml中的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!