Featured image of post Compressing, Exporting, Backing Up, and Importing Docker Images

Compressing, Exporting, Backing Up, and Importing Docker Images

Docker images can be compressed, exported, and imported using the Docker command line tools. Here are the specific steps: Compressing and exporting Dock...

Docker images can be compressed, exported, and imported using the Docker command line tools. Here are the detailed steps:

  1. Compress and Export the Docker Image

    Use the docker save command to compress the Docker image into a tar file, for example:

    1
    
    docker save -o my_image.tar my_image:tag
    

    This command saves the image named my_image with the tag tag as the file my_image.tar.

  2. Copy the Docker Image Tar File to Another Host

    Use the scp command or other file transfer tools to copy the Docker image tar file to another host, for example:

    1
    
    scp my_image.tar user@new_host:/tmp/
    

    This command copies the my_image.tar file to the /tmp/ directory on the target host.

  3. Import the Docker Image

    Use the docker load command to import the Docker image on the new host, for example:

    1
    
    docker load -i /tmp/my_image.tar
    

    This command extracts and imports the image file into the Docker engine.

  4. Verify the Docker Image

    After the import is complete, you can use the following command to verify if the Docker image has been successfully imported:

    1
    
    docker images
    

    This command lists all the images present in the local Docker engine, confirming that the required Docker image has been imported.

Compressing, Exporting, Backing Up, and Importing Docker Images

If the image is too large, you can compress it before exporting and then import it.

Image Compression for Export and Import

You can compress the image using the gzip tool:

1
docker save map-server-14:1.9 | gzip > docker-map-server-14_1.9.tar.gz

To decompress and import, use gunzip, which is typically bundled with most systems:

1
gunzip -c docker-map-server-14_1.9.tar.gz | docker load

In summary, exporting a Docker image requires using the docker save command to compress and save it, while importing a Docker image necessitates the docker load command for decompression and import. These commands facilitate the easy migration of applications between multiple Docker hosts.

Licensed under CC BY-NC-SA 4.0