Skip to content
Advertisement

Save multiple docker images using one command

Currently I am exporting docker images using below command

docker save imageName | gzip > imageName.tar.gz

docker save mysql | gzip > mysql.tar.gz

This command working fine for single image, i have tons of docker images in my local system, want to export. but i don’t know how to export all images which is available in docker images.

Please guide me how can i archive this by single command. which will save all images in current directory respectively ImageNames

Advertisement

Answer

docker save imageName1:tag1 imageName2:tag2 ... imageNameN:tagN | gzip > images.tar.gz

if you need to get all images, you might use something like this (but it might be getting a little too much, so be careful):

docker save $( 
    docker images 
        --format '{{.Repository}}:{{.Tag}}' 
        --filter "dangling=false" 
    | grep -v image_that_i_dont_want ) 
| gzip > images.tar.gz

EDIT:

in the event you need to save all images on a system in separate files:

for img in $( docker images --format '{{.Repository}}:{{.Tag}}' --filter "dangling=false" ) ; do
    base=${img#*/}
    docker save "$img" | gzip > "${base//:/__}".tar.gz
done
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement