更新
从docker-compose
1.28.0开始,新的服务配置文件就是为此而生的!您可以将profiles
服务标记为仅在特定配置文件中启动:
services:
client:
# ...
db:
# ...
npm:
profiles: ["cli-only"]
# ...
docker-compose up # start main services, no npm
docker-compose run --rm npm # run npm service
docker-compose --profile cli-only up # start main and all "cli-only" services
原始答案
从docker-compose
v1.5开始,可以使用flag传递多个docker-compose.yml
文件-f
。这允许您将开发工具拆分为单独docker-compose.yml
的,然后您只按需包含:
# start and attach to all your essential services
docker-compose up
# execute a defined command in docker-compose.dev.yml
docker-compose -f docker-compose.dev.yml run npm update
# if your command depends_on a service you need to include both configs
docker-compose -f docker-compose.yml -f docker-compose.dev.yml run npm update
有关这方面的深入讨论,请参阅docker/compose#1896。