Last active
May 4, 2021 07:47
-
-
Save VeikkoLehmuskorpi/25f8a31f25cf22401afcce316a0c07ad to your computer and use it in GitHub Desktop.
Search for a Docker container and view its logs
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
| #!/usr/bin/env bash | |
| # Searches the output of "docker ps" matching a string, | |
| # and views the logs of the first matching container | |
| # | |
| # Usage: | |
| # ./dlogs.sh <search_string> | |
| function dlogs() { | |
| if [ -z "$1" ] ; then | |
| echo "Usage: ./dlogs.sh <search_string>" | |
| exit 1 | |
| fi | |
| if docker ps | grep -i "$1" ; then | |
| docker logs --follow --timestamps \ | |
| $(docker ps | grep -i "$1" | awk '{print $1}' | head -1) | |
| else | |
| echo "no containers found matching '$1'" | |
| exit 1 | |
| fi | |
| } | |
| dlogs $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment