How to fail out loud while docker composing up -d?

Using docker-compose up -dwhen one of my containers does not start (i.e. the RUN command exits with an error code), it fails - how can I make it fail?

(Am I thinking about it right? My ultimate goal is to use Docker for my development environment. I would like to be able to deploy my environment and report errors right away. Until Docker, the true path is as much as possible, and I hesitate to depend on additional tools such as screen / tmux)

+4
source share
2 answers

Since you run it separately (-d), docker-compose only spawns containers and exits without controlling any problems. If you run containers in the foreground, follow these steps:

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

This should give you a pretty clear error for any problems with the container. Otherwise, I would recommend exploring some other more advanced schedulers that track running containers for crash recovery (like Universal Control Plane or Kubernetes).


Update. If you want a script for something outside docker-compose up -d, you can do

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

and if something is displayed there, you will have a container. There also docker-compose events | grep "container die".

+10
source

compose/cli/main.py#L66-L68, , docker-compose (Dockerfile):

except BuildError as e:
        log.error("Service '%s' failed to build: %s" % (e.service.name, e.reason))
sys.exit(1)

-d ( "", ) --abort-on-container-exit, " " :

+1

All Articles