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)

  • Docker - Execute a bash when running a container
  • Should I dockerize different servers running on a single machine?
  • Error in Docker: bad address to executables
  • How do you set up an elastic search cluster with multiple master nodes in docker compose?
  • Deploy a Dockerized Symfony2 application on AWS Elastic Beanstalk
  • Rails Puma inside of Docker Instance stops responding from inactivity
  • Join SwarmKit cluster with predefined token?
  • Docker supervisor - unable to find supervisor.conf file
  • How do I connect to the localhost of a docker container (from inside the container)
  • Docker compose not finding my index.js
  • rsync through ssh cannot find uppercase remote host (an other container in Docker)
  • What's a sane way to define custom travis job?
  • 2 Solutions collect form web for “How to fail loudly during docker-compose up -d?”

    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".

    As shown in compose/cli/main.py#L66-L68, docker-compose is supposed to fail on (Dockerfile) build:

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

    Since -d (Detached mode, which runs containers in the background) is incompatible with --abort-on-container-exit, a “docker way” would be to:

    • wrap the docker compose up -d in a script
    • add to that script a docker-compose logs), parsing for any error, and loudly exiting if any error message is found..
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.