Is there a way to stop a docker container, if a linked/upstream container is gone?

In my use case, I am having two docker-images ‘A’ and ‘B’, where ‘B’ kind of relies on an exposed port of container A.

# pseudo, Setup1
$ docker run -d A
aaaaa
$ docker run -d --link aaaaa B
bbbbb

This works just fine. If container “aaaaa” is not available, docker won’t let me start container of image B

  • Docker container inaccessible from host
  • How to make changes to the code inside a Docker Container?
  • localhost:8000 resolves to localhost and “this site can't be reached” but localhost:8000/services works
  • Where is the rootfs of container in host machine after docker 1.6.0
  • Docker on RHEL 7 in AWS can’t pull images
  • Retain environment variable values for Symfony2 app development in Docker
  • # pseudo, Setup2
    $ docker run -d --link aaaaa B
    docker: Error response from daemon: Cannot link to a non running container
    

    Just fine.

    Now, in my “Setup1”, I am stopping container “aaaaa”. Container “bbbbb” will just keep running. In my use case, I would like to stop this “dependent” container now. How can I achieve that?

  • How to setup Node environment variable in Dockerfile for running node.js application?
  • The “--cluster-store” and “--cluster-advertise” don't work
  • How to get docker container ID within Docker?
  • Atomic, Docker 1.10 and Openshift Origin 1.2 incompatibility
  • Error installing cafe with a Dockerfile
  • How to push only whats changed with Docker push?
  • One Solution collect form web for “Is there a way to stop a docker container, if a linked/upstream container is gone?”

    Docker 1.12. introduces HEALTHCHECK. As an ugly workaround, it works to place a killall or similar in the HEALTHCHECK-script.

    Maybe you are searching for docker-compose -> depends on.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.