Docker-compose exclude service by default

后端 未结 3 1445
栀梦
栀梦 2021-02-14 03:59

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

3条回答
  •  生来不讨喜
    2021-02-14 04:16

    Starting with docker-compose 1.28.0 the new service profiles are just made for that! With profiles you can mark services to be only started in specific profiles, for example:

    services:
      webapp:
        # ...
    
      nginx:
        # ...
        profiles: ["nginx"]
        ports:
          - 80:80
    
      ssl:
        # ...
        profiles: ["ssl"]
        ports:
          - 80:80
    
    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
    

    Depending on your exact use case/setup however it may be better to split your services into multiple docker-compose.yml files.

提交回复
热议问题