Use Bash to wait for Docker container to start by tag

If you run a container in the background and want to wait until it has started up before doing anything else, you can use a combination of docker ps and docker inspect to check within a Bash loop whether it is finally running. This can be useful if you want to run tests checking if the container is responding on a specific port for example.

You can remove the --all option for docker ps and the head pipe afterwards if you know there will only be a single running instance of the container tag, but the provided example is safer (as containers in “running” status should be at the top of the list)

Add comment