问题描述
我发现自己处于一种情况,我想暂时禁用 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 指出 在评论 顶级部分x-disabled:
(类似扩展字段)
5andr0 points out in the comments the top-level section x-disabled:
(an extension field-like)
更方便:将禁用的服务移动到顶级部分 x-disabled:
而不是 services:
带有 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 中的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!