Skip to content

Instantly share code, notes, and snippets.

@samir-plusb
Last active April 20, 2018 11:21
Show Gist options
  • Save samir-plusb/bbe5e53997f64a2e0515610854e66609 to your computer and use it in GitHub Desktop.
Save samir-plusb/bbe5e53997f64a2e0515610854e66609 to your computer and use it in GitHub Desktop.

Bash scripts to wait for a service (must be one-liner)

Wait for service on port to answer

while ! nc -z httpd 80; do sleep 0.1; done

Wait for docker image httpd to be available

while [[ ! -n "$(docker images -q httpd)" ]]; do echo "Image is not available..."; sleep 0.1; done

source: https://unix.stackexchange.com/questions/343942/shell-check-if-docker-container-is-existing

Wait for docker container httpd to be available

while [[ ! -n `docker ps --filter="name=httpd" -q` ]]; do echo "Waiting for docker container to start..."; sleep 0.1; done

source: https://serverfault.com/questions/704373/shell-script-for-docker-ps-a-grep-to-find-number-of-certain-containers-runnin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment