Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Docker utils
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
#!/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
#!/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
ls *.tar.gz | while read IMAGE; do
echo "unpigz --stdout $IMAGE | docker load"
unpigz --stdout $IMAGE | docker load
done
#!/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
#!/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
#!/bin/bash
docker rm -v $(docker ps -f 'status=exited' -q)
#!/bin/bash
exec docker rmi $(docker images -qf "dangling=true")
#!/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
You can’t perform that action at this time.