[Experience] The difference between Docker export and save

Source: Internet
Author: User
Tags docker ps docker run

A running image is called a container. You can modify the container (such as deleting a file), but these changes do not affect the image. However, you can use the Docker commit command to turn a running container into a new image.

The Export command is used to persist the container (not mirroring). Therefore, we need to get the container ID by the following methods:

sudo docker ps-a
Then perform the export:

sudo docker export <container id> >/home/export.tar

The Save command is used to persist the image (not the container). Therefore, we need to get the image name by the following methods:

sudo docker images

Then execute the Save:

sudo docker save busybox-1 >/home/save.tar

The final result is a 2.8MB size tar file (slightly larger than using the Export command)

You can use Docker rm (Dockerps−q−a) to remove all containers at once, Dockerrmi (Docker ps-q-a) deletes all the containers at once, and Docker RMI (Docker images-q) deletes all the mirrors at once.

Now start importing the container you just exported:

# import Export.tar file
Cat/home/export.tar | sudo docker import-busybox-1-export:latest

# View image
sudo docker image S

# to check if the import is successful, is to start a new container, check if there is a/home/test directory (exists)
sudo docker run Busybox-1-export [-d/home/test] && Echo ' Directory found ' | | Echo ' Directory not found '

Use similar steps to import the image:

# import Save.tar file
Docker load 

The exported version will be slightly smaller than the original version. That's because after exporting, history and metadata are lost. Execute the following command to find out:

# Show all layers of mirroring (layer)
sudo docker images--tree

Save and Reload (saveed-loaded) without losing the history and layers (layer) of the mirror. This means that you will not be able to roll back to the previous layer (layers) using the export and then import, and then you can roll back the entire image using the Save and reload mode (you can perform Docker tag <layer id> <image NAME > Roll back to the previous layer).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.