Skip to content

Instantly share code, notes, and snippets.

@jesse-c
Created August 1, 2017 07:49
Show Gist options
  • Save jesse-c/f74e871b4c783e1bd69ca17f9e1b9156 to your computer and use it in GitHub Desktop.
Save jesse-c/f74e871b4c783e1bd69ca17f9e1b9156 to your computer and use it in GitHub Desktop.
Wait for Docker container to start and immediately follow its logs
#!/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