Search code examples
dockerdocker-compose

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" ?


Solution

  • You could simply redefine the entrypoint or command in order to replace said command with something which does nothing (/bin/true)

    That would make the container exit immediately, doing nothing.


    shadi adds the following tips in the comments:

    If you don't want the service to get built at all, redefine the build key to point to a Dockerfile that only has:

    FROM tianon/true 
    ENTRYPOINT ["/true"]
    

    5andr0 points out in the comments the top-level section x-disabled: (an extension field-like)

    Far more convenient: moving disabled services to the top-level section x-disabled: instead of services:

    Sections with the x- prefix will be parsed, but ignored if not used in the intended way as an extension field.