Last active
July 3, 2020 08:15
-
-
Save byrnedo/29229bddaedff162f634 to your computer and use it in GitHub Desktop.
Docker helpers ( simple colour docker ps )
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
RED=`echo -e '\033[101m\033[37m'` | |
GREEN=`echo -e '\033[102m'` | |
DARK_RED=`echo -e '\033[41m\033[37m'` | |
DARK_GREEN=`echo -e '\033[42m'` | |
NORMAL=`echo -e '\033[0m'` | |
#Docker aliases | |
function dps(){ | |
docker ps --format "{{.ID}}\t{{.Image}}\t{{.Labels}}"| \ | |
sed -e "s/:/ :/" | \ | |
column -t | \ | |
sed -e "1~2s#/\(.*\):#/$GREEN\1$NORMAL:#" -e "1~2s/:\(.*\)/$RED\1$NORMAL/" | \ | |
sed -e "0~1s#/\(.*\):#/$DARK_GREEN\1$NORMAL:#" -e "0~1s/:\(.*\)/$DARK_RED\1$NORMAL/" | |
} | |
function watchDps(){ | |
while true | |
do | |
clear | |
dps | |
echo Last Updated $(date) | |
sleep 2 | |
done | |
} | |
# Run a command if the image for a container changes. | |
function onImageChanged(){ | |
local image=$1 | |
local commandToRun=$2 | |
echo $image: $commandToRun | |
local initialID="$(curl -s localhost:2375/images/${image}/json|sed 's/.*"Created":"\([A-Z0-9:.-]*\)".*/\1/')" | |
while true | |
do | |
local newID="$(curl -s localhost:2375/images/${image}/json|sed 's/.*"Created":"\([A-Z0-9:.-]*\)".*/\1/')" | |
if [[ $newID != $initialID ]] | |
then | |
initialID=$newID | |
echo Image changed. | |
bash -c "$commandToRun" | |
fi | |
sleep 2 | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment