Created
December 18, 2018 03:06
-
-
Save yijia2413/ca971e01e70fb9ef0568b1b4ed4ffc5e to your computer and use it in GitHub Desktop.
useful docker scripts
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
#!/bin/bash | |
set -ex | |
containers=$(docker ps -a -q --filter status=exited) | |
if [[ ! -z ${containers} ]]; then | |
docker rm -f -v ${containers} | |
fi | |
images=$(docker images | grep none | awk '{print $3}') | |
if [[ ! -z ${images} ]]; then | |
docker rmi -f ${images} | |
fi |
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
#!/bin/bash | |
# set -ex | |
imgs=$(docker images --format "table {{.ID}}_{{.Repository}}_{{.Tag}}" | sed 1d) | |
for line in ${imgs}; do | |
imgid=$(echo ${line} | cut -d "_" -f1) | |
dst=$(echo ${line} | sed -e "s/\//./g").tar | |
if [[ -e ${dst} ]]; then | |
continue | |
fi | |
echo "saving ${dst}" | |
docker save ${imgid} > ${dst} | |
done |
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
#!/bin/bash | |
# set -ex | |
for tar in $(ls | grep tar); do | |
echo "Loding ${tar} " | |
docker load < ${tar} | |
imgid=$(echo ${tar} | cut -d "_" -f1) | |
name=$(echo ${tar} | cut -d "_" -f2 | sed -e "s/\./\//g") | |
tag=$(basename $(echo ${tar} | cut -d "_" -f3) .tar) | |
echo "Taging ${imgid} to ${name}:${tag}" | |
docker tag ${imgid} ${name}:${tag} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment