Running container in detached mode from compose.yml

I’m starting up a few containers with a docker-compose.yml file and would like at least some of them to start in detached mode.

I can pass this at command line with

docker-compose up -d

But I wonder if it’s possible to specify this sort of thing in the yml file?

3 Likes

I also have this question. Is it not possible?

Is there anybody out there that can answer the question. I too would like to know if its possible to declare detached mode in the compose YAML file.

FD

I’m really not sure if you guys still have a doubt on this.
But, docker-compose up -d worked pretty well for me.
I am using it in a jenkins pipeline, taking everything from a docker-compose.yml file
Hope this helps someone with same doubt.
there is information available on official docker docs page https://docs.docker.com/compose/reference/up/ too

For docker-compose deployments, all supported configuration items are listed here:

There is no mystery about this: something not listed in the refence, is simply something that is not covered by docker compose files.

In your docker-compose.yml set attach: false as a top-level configuration under the service you wish to detach.

This was introduced in version 2.20.

For instance, if you wanted Redis as a service, but did not want to see the Redis logs in your terminal, your compose file would look something like this.

services:
     redis:
          image: redis:latest
          attach: false

See documentation.