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)
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!
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.
Stops containers and removes containers, networks, volumes, and images created by 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.
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"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With