ccl*_*oyd 3 docker docker-compose
如果我在docker-compose项目中定义了很多服务,如何从默认docker-compose up
命令中排除服务?
例如,我有一个nginx服务和一个ssl服务。它们之所以发生冲突是因为它们都占用了端口80,因此,如何使该端口生效,除非我专门运行该服务,否则ssl服务才能启动,并且默认情况下,该up
命令将执行除ssl服务以外的所有操作?
acr*_*ran 22
从docker-compose
1.28.0开始,新的服务配置文件就是为此而制作的!随着profiles
您可以标记服务,在特定的配置文件来才开始,例如:
services:
webapp:
# ...
nginx:
# ...
profiles: ["nginx"]
ports:
- 80:80
ssl:
# ...
profiles: ["ssl"]
ports:
- 80:80
Run Code Online (Sandbox Code Playgroud)
docker-compose up # start only your webapp services
docker-compose --profile nginx up # start the webapp and nginx service
docker-compose --profile ssl up # start the webapp and ssl service
docker-compose run ssl # run the ssl service
Run Code Online (Sandbox Code Playgroud)
根据您的确切用例/设置,但是最好将您的服务拆分为多个docker-compose.yml
文件。
Ent*_*ack 17
嘿,我今天在 github 上遇到了这个问题:“定义默认情况下未启动的服务” https://github.com/docker/compose/issues/1896
嗯,你不能。但是我已经完成了这个解决方法,因为我有很多服务并且添加了更多服务。我只用一些虚拟图像和自定义命令做了虚拟服务,然后我将所需的服务设置为依赖项:
main-services:
image: docker4w/nsenter-dockerd # you want to put there some small image
command: sh -c "echo start"
depends_on:
- postgres
- consumer-backend
- prisma
- api-gateway
- adminer
- frontend
Run Code Online (Sandbox Code Playgroud)
然后我在我的 readme.md 中写道:
使用它来运行一切
docker-compose up -d main-services
创建数据库结构
docker-compose up deploy
包含数据的种子数据库
docker-compose up seed
到目前为止,使用虚拟服务对事物进行分组比我见过的任何其他东西都容易。
并非完全符合您的要求,但是您可以使用scale标志将ssl服务缩放为零:
docker-compose up --scale ssl_service=0
Run Code Online (Sandbox Code Playgroud)
另一个选择是拥有多个撰写文件,并使用带有-f
标志的docker运行docker 以启动特定服务。
归档时间: |
|
查看次数: |
2342 次 |
最近记录: |