A pure shell script waiting for provided command to exit with zero code.
Inspired by eficode/wait-for but allows to use any custom command instead of netcat
.
There are two options:
-
download script
wait-for-cmd.sh
:wget https://raw.githubusercontent.com/vitalets/wait-for-cmd/master/wait-for-cmd.sh chmod +x ./wait-for-cmd.sh
-
run as docker container:
docker run --rm vitalets/wait-for-cmd 'curl -f https://example.com > /dev/null 2>&1'
./wait-for-cmd.sh COMMAND [TIMEOUT]
Wait for HOST:PORT
ready with netcat
:
./wait-for-cmd.sh 'nc -z example.com 80 > /dev/null 2>&1'
Wait for HTTP status 2xx with curl
:
./wait-for-cmd.sh 'curl -f https://example.com > /dev/null 2>&1'
Wait for HTTP status 2xx with wget
:
./wait-for-cmd.sh 'wget --timeout=1 -q https://example.com -O /dev/null > /dev/null 2>&1'
Wait for Docker container running (note $
before command):
./wait-for-cmd.sh $'[ "$(docker inspect my_container -f \'{{.State.Status}}\')" == "running" ]'
Wait for Docker container healthy (note $
before command):
./wait-for-cmd.sh $'[ "$(docker inspect my_container -f \'{{.State.Health.Status}}\')" == "healthy" ]'
Wait for localhost:port
from inside Docker container (note host.docker.internal
instead of localhost
):
docker run --rm vitalets/wait-for-cmd 'curl -f http://host.docker.internal:3000 > /dev/null 2>&1'
./test.sh
docker build -t vitalets/wait-for-cmd .
docker push vitalets/wait-for-cmd
MIT @ Vitaliy Potapov