Created
August 1, 2017 07:49
-
-
Save jesse-c/f74e871b4c783e1bd69ca17f9e1b9156 to your computer and use it in GitHub Desktop.
Wait for Docker container to start and immediately follow its logs
This file contains 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 -e | |
# Example: | |
# | |
# 1. In a terminal window: ./waitforandfollow.sh hello-world | |
# 2. In another terminal window: docker run hello-world | |
if [ "$#" -ne 1 ] ; then | |
echo "$0: exactly 1 argument expected." | |
exit 3 | |
fi | |
found=false | |
cid="" | |
while [ "$found" = false ] | |
do | |
for id in $(docker ps --filter ancestor="$1" --format="{{.ID}}"); do | |
if [ "$id" != "" ] ; then | |
found=true | |
cid="$id" | |
fi | |
done | |
done | |
docker logs -f "$cid" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment