Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fail loudly during docker-compose up -d?

Using docker-compose up -d, when one of my containers fails to start (i.e. the RUN command exits with an error code), it fails quietly - How can I make it fail loudly?

(Am I thinking about this the right way? My ultimate goal is using Docker for my development environment. I'd like to be able to spin up my environment and be informed of errors right away. I'd like to stay to Docker's true path as much as possible, and am hesitant to depend on additional tools like screen/tmux)

like image 652
Gabe Kopley Avatar asked Jun 15 '16 20:06

Gabe Kopley


People also ask

How do you destroy a docker compose?

If you do, killing multiple containers takes one command: docker-compose down. You could also run docker-compose without detached mode. If so, you'll just use ^C to kill all containers. And there you have it—all containers killed!

How do I stop after docker compose up?

If you only want to stop the containers for your project, in the project directory, run docker-compose stop or press Ctrl-C to stop a docker-compose process running in the foreground and then run docker-compose stop to ensure the project containers have stopped.

Does docker compose down destroy volumes?

Stops containers and removes containers, networks, volumes, and images created by up .

What happens during docker compose up?

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.


1 Answers

Since you are running it detached (-d), docker-compose only spawns the containers and exits, without monitoring for any issues. If you run the containers in the foreground with:

docker-compose up --abort-on-container-exit

That should give you a pretty clear error on any container problems. Otherwise, I'd recommend looking into some of the other more advanced schedulers that monitor the running containers to recover from failures (e.g. Universal Control Plane or Kubernetes).


Update: If you want to script something outside of the docker-compose up -d, you can do a

docker events -f "container=${compose_prefix}_" -f "event=die"

and if anything gets output there, you had a container go down. There's also docker-compose events | grep "container die".

like image 172
BMitch Avatar answered Sep 24 '22 10:09

BMitch