Last active
May 31, 2018 18:06
-
-
Save ryansch/7618851f2c2bf7dc9dadf6f1f241fafa to your computer and use it in GitHub Desktop.
Docker utils
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 images | tail -n +2 | grep -v "none" | awk '{printf("%s:%s\n", $1, $2)}' | while read IMAGE; do | |
echo $IMAGE | |
filename="${IMAGE//\//-}" | |
filename="${filename//:/-}.docker-image.tar.gz" | |
docker save ${IMAGE} | pigz --stdout > $filename | |
done |
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
#!/bin/bash | |
VOLUME=${1:?'Volume name required as first argument'} | |
volume_switches="-v ${VOLUME}:/source/${VOLUME}" | |
set -x | |
docker run -it --rm \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v /bin/docker:/bin/docker \ | |
-v $(pwd):/backup \ | |
${volume_switches} \ | |
outstand/dockup:latest backup |
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
#!/bin/bash | |
if [ ! -f volumes ]; then | |
echo 'Expected `volumes` file to exist' | |
exit 1 | |
fi | |
volume_switches="" | |
while read VOLUME; do | |
echo $VOLUME | |
volume_switches="${volume_switches} -v ${VOLUME}:/source/${VOLUME}" | |
done <<< "$(cat volumes)" | |
set -x | |
docker run -it --rm \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v /bin/docker:/bin/docker \ | |
-v $(pwd):/backup \ | |
${volume_switches} \ | |
outstand/dockup:latest backup |
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
ls *.tar.gz | while read IMAGE; do | |
echo "unpigz --stdout $IMAGE | docker load" | |
unpigz --stdout $IMAGE | docker load | |
done |
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
#!/bin/bash | |
if [ -z "$1" ]; then | |
echo 'Volume name required' | |
exit 1 | |
fi | |
VOLUME="$1" | |
volume_switches="-v ${VOLUME}:/source/${VOLUME}" | |
set -x | |
docker run -it --rm \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v /bin/docker:/bin/docker \ | |
-v $(pwd):/backup \ | |
${volume_switches} \ | |
outstand/dockup:latest restore |
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
#!/bin/bash | |
if [ ! -f volumes ]; then | |
echo 'Expected `volumes` file to exist' | |
exit 1 | |
fi | |
volume_switches="" | |
while read VOLUME; do | |
echo $VOLUME | |
volume_switches="${volume_switches} -v ${VOLUME}:/source/${VOLUME}" | |
done <<< "$(cat volumes)" | |
set -x | |
docker run -it --rm \ | |
-v /var/run/docker.sock:/var/run/docker.sock \ | |
-v /bin/docker:/bin/docker \ | |
-v $(pwd):/backup \ | |
${volume_switches} \ | |
outstand/dockup:latest restore |
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
#!/bin/bash | |
docker rm -v $(docker ps -f 'status=exited' -q) |
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
#!/bin/bash | |
exec docker rmi $(docker images -qf "dangling=true") |
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
#!/bin/bash | |
if [ "$1" = '--force' ]; then | |
echo '==> Removing volumes' | |
docker volume rm $(docker volume ls -q -f 'dangling=true' | egrep -v '^[^0-9]+$') | |
echo '==> Done' | |
else | |
echo '==> Volumes to be deleted' | |
docker volume ls -q -f 'dangling=true' | egrep -v '^[^0-9]+$' | |
echo '==> Run again with --force option to remove' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment