Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background/foreground with docker-compose

Sometimes, when I do "docker-compose up -d", I forget the "-d" part. So it starts to show me starting logs and if I do Ctrl + C it just terminates all the process and shows me the closing logs.

I have several questions about this :

  1. If I manage to detach the process with detach keys (Ctrl P Ctrl Q by default) is it the exact same result as if I had started docker-compose with -d ?

  2. Now if detach keys don't work (impossible to input Ctrl Q) is it the same result to do "Ctrl-Z" bg compared to starting docker-compose with -d ?

like image 485
Tristan Avatar asked Mar 17 '17 07:03

Tristan


People also ask

Does docker compose up run in background?

By default, a Docker Compose starts the services in the foreground mode just like a docker run command. To run the Docker Compose in the background, a docker-compose up command should be started with the -d or --detach option.

How do I run a container in detached mode in docker compose?

Run Docker Compose in detached mode by passing the -d flag to docker-compose up . Use docker-compose ps to review what you have running.

What is docker composed detached mode?

The docker compose up command aggregates the output of each container (like docker compose logs --follow does). When the command exits, all containers are stopped. Running docker compose up --detach starts the containers in the background and leaves them running.

Does docker compose up build images?

Step 4: Build and run your app with Compose From your project directory, start up your application by running docker compose up . Compose pulls a Redis image, builds an image for your code, and starts the services you defined.


1 Answers

docker-compose up displays streaming logs. This is the main advantage over docker-compose up -d.

If you ran docker-compose up -d, it's never too late. You are still able to display those streaming logs:

docker-compose logs -f
like image 187
Abdennour TOUMI Avatar answered Sep 20 '22 00:09

Abdennour TOUMI