NOTE: make sure you export containers and images in separate directories or it's very likely there will be issues when importing or loading your backups using the following snippets
$ while read image container_id; do
docker export $container_id > ${image////_}-${container_id}.tar
done < <(docker ps -a -f status=exited | tail -n +2 | awk '{ print $2 " " $1 }')
$ for file in *.tar; do
eval `echo $file | sed -nr 's;([a-zA-Z0-9\.-]+)_([a-zA-Z0-9-]+)-([a-f0-9]+)\.tar;IMAGE=\1/\2\nVERSION=\3;pg'
cat $file | docker import - ${IMAGE}:${VERSION}
done
$ while read image version image_id; do
docker save $image_id > ${image////_}-${version}-${image_id}.tar
done < <(docker images| tail -n +2 | grep -v '<none>' | awk '{ print $1 " " $2 " " $3 }')
$ for image in *.tar; do docker load < $image; done
For the "Export all containers" I needed to replace
${image////_}
with${image//\//_}
, i.e. escape the to-be-replaced slash.However, these scripts are very helpful to me! Thanks a lot!