Last active
August 25, 2020 12:56
-
-
Save exaV/612fcfa2d68ea9150d2451bd05562116 to your computer and use it in GitHub Desktop.
A fuzzy wrapper for the docker cli. Execute a docker command for all containers who match a search term. Do something sensible if no command or no search terms are provided.
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
docker_ps_formatted(){ docker ps -a --format "table {{.Names}}\t{{.Image}}\t{{.Status}}\t{{.Ports}}" } | |
# dockerg [ARGS] SEARCH | |
# basically docker ps | grep SEARCH | xargs docker ARGS | |
# but all args are optional | |
# e.g. 'dockgerg bank' -> check which services are found; dockgerg logs --tail 15 bank -> log the service | |
# e.g. 'dockerg start Exited' -> start all containers with status 'Exited' | |
dockgerg(){ | |
if [ "$#" -eq 0 ]; then docker_ps_formatted; return; fi | |
SEARCH=${@:$#}; | |
if [ "$#" -eq 1 ]; then docker_ps_formatted | grep $SEARCH; return; fi | |
ARGS=${@:1:$# - 1}; | |
docker_ps_formatted | grep $SEARCH | awk "{print \$1}" | xargs docker $(echo $ARGS); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment