Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to disable a service in docker-compose.yml

I find myself in the situation, that I want to disable a service temporarily in a docker-compose file.

Of course I could comment it out, but is there any option to just say "enabled: false" ?

like image 967
Mandragor Avatar asked Oct 10 '22 03:10

Mandragor


People also ask

How do I stop a specific service in Docker compose?

To stop a docker application that is running in the foreground, you just have to press Ctrl-C as show above. But, to stop a docker application that is running in the background, use the docker-compose stop as shown below.


1 Answers

As of January 2021, there is a way to elegantly disable a service within the docker-compose.yml or to selectively run some services and not others. Docker Compose 1.28.0 introduced support for a profiles key. Now we can do something like:

version: "3.9"
services:
  base_image:
    ...
    profiles:
      - donotstart

Examples in the documentation describe how to use this key to create groups of containers that run together based on a --profile option on the command line. Check out the page here: https://docs.docker.com/compose/profiles/

Update

Support for profiles is working correctly in Compose V2 beta 5 (docker compose). Compose V2 beta 6 has been included in Docker Desktop 3.5.2 released 2021-07-08.

like image 167
mcarson Avatar answered Oct 11 '22 15:10

mcarson