What is the difference between save and export in Docker?
Solution 1:
The short answer is:
-
save
will fetch an image : for a VM or a physical server, that would be the installation .ISO image or disk. The base operating system.It will pack the layers and metadata of all the chain required to build the image. You can then load this "saved" images chain into another docker instance and create containers from these images.
-
export
will fetch the whole container : like a snapshot of a regular VM. Saves the OS of course, but also any change you made, any data file written during the container life. This one is more like a traditional backup.It will give you a flat .tar archive containing the filesystem of your container.
Edit: as my explanation may still lead to confusion, I think that it is important to understand that one of these commands works with containers, while the other works with images.
An image has to be considered as 'dead' or immutable, starting 0 or 1000 containers from it won't alter a single byte. That's why I made a comparison with a system install ISO earlier. It's maybe even closer to a live-CD.
A container "boots" the image and adds an additional layer on top of it. This layer stores any change on the container (created/changed/removed files...).
Solution 2:
There are two main differences between save
and export
commands.
save
command saves whole image with history and metadata butexport
command exports only files structure (without history and metadata). So the exported tar file will be smaller then the saved one.When you use exported file system for creating a new image then this new image will not contain any
USER
,EXPOSE
,RUN
etc. commands from your Dockerfile. Only file structure will be transferred. So when you are using mentioned keywords in your Dockerfile then you cannot use export command for transferring image to another machine - you need always use save command.