有什么方法可以禁用 docker-compose.yml 中的服务 [英] Is there any way to disable a service in docker-compose.yml

查看:34
本文介绍了有什么方法可以禁用 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" ?

推荐答案

你可以简单地重新定义 entrypointcommand 以便用什么都不做的东西替换所述命令 (/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:

If you don't want the service to get built at all, redefine the build key to point to a Dockerfile that only has:

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:

Far more convenient: moving disabled services to the top-level section x-disabled: instead of 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 中的服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆