A tiny (~3MB) netcat-driven docker image which continuously tries connecting to a specified TCP/IP endpoint, and exits when the connection is established. Running it in the foreground allows blocking the execution of some context (e.g., deploy script), unless dependent services are up.
$ docker run --rm igops/wait-for-port HOST PORT
E.g.,
$ docker run --rm igops/wait-for-port 172.17.0.1 80
will query 172.17.0.1:80
each 0.1s
, and exit when the connection is established:
Waiting for 172.17.0.1:80...
OK
#!/bin/sh
docker run --rm -d -p 80:80 nginx
docker run --rm --add-host="host:host-gateway" igops/wait-for-port host 80
curl -XGET 'http://localhost'
Output:
Waiting for host:80...OK
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
#!/bin/sh
docker run --rm --add-host="host:host-gateway" igops/wait-for-port host 22
echo "SSH server is running"
#!/bin/sh
docker network create my-bridge
docker run --rm -d --net my-bridge --net-alias my-mongo mongo
docker run --rm --net my-bridge igops/wait-for-port my-mongo 27017
echo "MongoDB is up"
#!/bin/sh
docker run --rm -d -p 27017:27107 mongo
docker run --rm --add-host="docker-host:host-gateway" igops/wait-for-port docker-host 27017
echo "MongoDB is up"
Variable | Description |
---|---|
CHECK_FREQUENCY | Port scanning frequency in seconds, 0.1 is the default |