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

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.

Temporarily Disable/Enable containers in a docker-compose.yaml , Suggestion: Add a docker-compose.yml service configuration option to call it) that, when false (default value: true), causes the given service to not be dependencies, so I have no strong feelings on this aspect either way). One way to achieve that is to define your optional service in a different compose file. Then to start the optional service, run: $ docker-compose -f docker-compose.yml -f optional-service.yaml up For example, if I have a docker-compose.yml file that looks like:

You can do it in a docker-compose.override.yaml file.

This file is automatically read by docker-compose and merged into the main docker-compose.yaml.

If you have it excluded from Git, each developer can tweak the configuration (with a few limitations) without changing the original docker-compose.yaml.

So, service foo can be disabled ad-hoc by redefining its entrypoint in docker-compose.override.yaml:

version: "3"

services:
  foo:
    entrypoint: ["echo", "Service foo disabled"]

Give services an option to disable automatic startup on "up" · Issue , docker-compose stop. Estimated reading time: 1 minute. Usage: stop [options] [​SERVICE] Options: -t, --timeout TIMEOUT Specify a shutdown timeout in  docker-compose -f docker-compose.yml -f docker-compose.override.yml -f docker-compose.production.yml up And the production.yml would remove the binds. There are probably better ways to achieve this, but this is a real world use case. I mean, I could have a .development.yml file that I always have to use in development and if I don't it's

I add the following extra line to the service I want to temporarily disable:

command: echo "{put your service name here} disabled"

It starts anyway, but does nothing.

docker-compose stop, yml also specifies this same service, any matching fields override the previous file. New values, add to the webapp service configuration. webapp: build: . In the our project architecture, the docker-compose.yml file is not used for cloud deployments, but only for configuration of the local server. On the cloud, the deployment is taken care of by dedicated systems on our servers. This means that entries in or changes to docker-compose.yml will not affect cloud deployments in any way.

There is no way to disable a service defined in Docker compose yaml file. VonC's suggestion is a good workaround Please see below the docker compose documentation for available options https://docs.docker.com/compose/compose-file/

Overview of docker-compose CLI, For full details on what each version includes and how to upgrade, see About versions and upgrading. This table shows The Compose file is a YAML file defining services, networks and volumes. dockerfile. Alternate Dockerfile. Compose uses an alternate file to build with. Use none to disable networking during build:. It is already possible to define a service which is not long-running, not exposing any ports and is not an essential part of the application in a totally valid docker-compose.yml. In fact this is also one of the suggested workarounds! Just split the tasks into a separate docker-compose.yml.

I would scale the service to 0 replicas with: deploy: replicas: 0

Unfortunately as the documentation states this only works with docker swarm.

Compose file version 3 reference, For full details on what each version includes and how to upgrade, see About The Compose file is a YAML file defining services, networks and volumes. To disable any default healthcheck set by the image, you can use disable: true . Hi guys ! When doing a docker-compose -f /a/b/c/docker-compose.yml pull from /a -> it works. When doing a docker-compose -f /a/b/c/docker-compose.yml pull from /a/foo/bar -> it does not work: ERROR: .IOError: [Errno 2] No such file or di

Compose file version 2 reference, Compose stop attempts to stop a container by sending a SIGTERM . It If you are able, modify the application that you're running to add an explicit signal handler for SIGTERM . How do I run multiple copies of a Compose file on the same host? Use up to start or restart all the services defined in a docker-​compose.yml . The default path for a Compose file is ./docker-compose.yml. Tip: You can use either a .yml or .yaml extension for this file. They both work. A service definition contains configuration that is applied to each container started for that service, much like passing command-line parameters to docker run.

Frequently asked questions, Define the services that make up your app in docker-compose.yml so they can be Start, stop, and rebuild services; View the status of running services; Stream the log When docker-compose up runs, if it finds any containers from previous runs, it The Compose file provides a way to document and configure all of the  The default path for a Compose file is ./docker-compose.yml. Tip: You can use either a .yml or .yaml extension for this file. They both work. A service definition contains configuration that is applied to each container started for that service, much like passing command-line parameters to docker run.

Overview of Docker Compose, How to use Docker Compose's extends keyword to share configuration Extending an entire Compose file by using multiple Compose files; Extending This deploys all three services using the configuration in docker-compose.yml and Convert an account into an organization · Deactivate an account or an organization. There are however, already a few ways to handle this scenario: you can include the service in the config with a no-op cmd, and then later run it with docker-compose run you could exclude it from the core config, and instead include it in a config that uses extends to pull in services from the core config

Comments
  • The answer is: "it depends" ... on what you are trying to accomplish. If you run docker-compose up it will start all the services by default. However, if you run docker-compose up myservice it will start myservice and things that depend on it. By setting up the dependencies you can make it so the bad service doesn't start with this command. You can also do docker-compose run to get just the services you want. The right choice may also be to break this into multiple compose files to allow you the flexibility you need.
  • In order to handle a similar need I had, I play with depends_on and the service argument in docker-compose up, or the option --no-deps in case you don't want to start the dependencies. I know is not what you are looking for, but is the other way around.
  • Another option is create as many docker-compose files as you need, and pick which of them you want to include in your calls docker-compose -f docker-compose.yml -f another-docker-compose.yml up -d. You can check the resultant docker compose merge with the config command: docker-compose -f docker-compose.yml -f another-docker-compose.yml config
  • Does this answer your question? Can you define optional docker-compose services?
  • @EshaanBansal I don't know of such a feature.
  • I would also add/change restart: "no" to avoid infinite restarts
  • This does not help in the case that the reason what you want to disable this service is because the service can not even start. In my case, I postgres does not start because there is another instance of postgres running, and the ports command causes conflicts. I could start changing the definition, but at that point commenting the whole thing out is easier.
  • Far more convenient: moving disabled services to the top-level section x-disabled: instead of services:
  • @5andr0 Interesting. Is there a documentation for that docker-compose section?
  • docs.docker.com/compose/compose-file/#extension-fields introduced in v3.4. Sections with the x- prefix will be parsed, but ignored if not used in the intended way as an extension field
  • If you have a "restart: unless-stopped" etc comment out that, or it will continuously restart