Docker-compose exclude service by default

两盒软妹~` 提交于 2020-04-10 04:00:30

问题


If I have a great many services defined in a docker-compose project, how can I exclude a service from the default docker-compose up command?

For example, I have an nginx service, and an ssl service. They conflict because they both consume port 80, so how can I make it so that the ssl service doesn't start unless I specifically run that service, and by default the up command will do everything EXCEPT the ssl service?


回答1:


Not exactly what you're looking for but you could use the scale flag to scale your ssl service to zero:

docker-compose up --scale ssl_service=0

Another option is to have multiple compose files and run docker with the -f flag to start specific services.




回答2:


Hey I hit this question on github today: "Define services which are not started by default" https://github.com/docker/compose/issues/1896

Well, you can't. But I have done this workaround since I have quite a lot of services and adding more. I did dummy service with just some dummy image and custom command and then I set my desired services as dependencies:

  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

Then I wrote into my readme.md:

Use this to run everything
docker-compose up -d main-services

Create database structures
docker-compose up deploy

Seed database with data
docker-compose up seed

Using dummy services to group things was easier than anything else I have seen so far.



来源:https://stackoverflow.com/questions/50848797/docker-compose-exclude-service-by-default

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!