Last active
July 29, 2023 02:28
-
-
Save magickatt/9d6177dc36b083410cc0debabca080cd to your computer and use it in GitHub Desktop.
Use Bash to wait for container to start
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
IMAGE_NAME=test-1 | |
# 1-liner | |
until [ $(docker inspect -f "{{json .State.Status }}" $(docker ps -a -q --filter ancestor=$IMAGE_NAME --format="{{.ID}}" | head -n 1)) == '"running"' ]; do echo "Waiting for container to start..." && sleep 1; done | |
# More readable | |
CONTAINER_ID=$(docker ps --all --quiet --filter ancestor=$IMAGE_NAME --format="{{.ID}}" | head -n 1) | |
CONTAINER_STATUS=$(docker inspect --format "{{json .State.Status }}" $CONTAINER_ID) | |
until [ $CONTAINER_STATUS == '"running"' ] | |
do | |
echo "Waiting for container to start..." | |
sleep 1 | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment