Skip to content

Instantly share code, notes, and snippets.

@yijia2413
Created December 18, 2018 03:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yijia2413/ca971e01e70fb9ef0568b1b4ed4ffc5e to your computer and use it in GitHub Desktop.
Save yijia2413/ca971e01e70fb9ef0568b1b4ed4ffc5e to your computer and use it in GitHub Desktop.
useful docker scripts
#!/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
#!/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
#!/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