docker-wait is a really small Docker utility that blocks until other container(s) is(are) accepting TCP connections, and errors-out if it cannot connect within a given timeout.
Possible uses are:
- in CI environments, to ensure that containers are up before tests begin running against them
- in a deployment pipeline, to assure the correct startup sequence (orchestrator-like)
The default operation looks up all the
EXPOSE-d ports of all the linked containers and waits for them.
$ docker run -d --name nasturzo some-image-or-other $ docker run --rm --link nasturzo netservice/docker-wait waiting for 172.17.0.106:8080 .. up! Everything is up and listening
It doesn't matter what the link aliases are.
- you want to wait for only a subset of the links/ports, or
- you want to connect to hosts/ports that haven't been linked explicitly via --link, or
- you want to check hosts are outside the containerized environment you're running inside
then you can provide a comma-delimited list of host:port targets in the
$ docker run --rm -e TARGETS=18.104.22.168:53,github.com:443 netservice/docker-wait waiting for 22.214.171.124:53 .up! waiting for github.com:443 . up! Everything is up and listening
By default each connection attempt will give up after 10 seconds. You can specify a custom timeout via the
TIMEOUT env variable:
$ docker run --rm -e TARGETS=github.com:5432 -e TIMEOUT=25 netservice/docker-wait waiting for github.com:5432 ......................... ERROR: unable to connect
If any TARGET times out, the
docker-wait container immediately exits with status code 1.
It's a good practice IMHO to run this kind of container and delete it immediately afterwards, using --rm or remove:true. Running a docker-gc or a cleanup script regularly it's another thing.