over Docker export and import.
This serves as a reminder for me as I often mixed up myself.
Save vs Export
As per documentation, save produces a tar file that contains
all parent layers, and all tags + versions, or specified repo:tag, for each argument provided
docker save busybox:latest > busybox.tar
while export also produces a tar file, it only exports the content without layer/history
export the contents of the underlying directory
docker export busybox:latest > busybox.tar
What this also means is that using the
export will result in a smaller size image due to flattening.
Load vs Import
load restores the full history and layers from what was
Load an image or repository from a tar archive (even if compressed with gzip, bzip2, or xz) from a file or STDIN. It restores both images and tags.
docker load < busybox.tar
while import just creates the filesystem with the
Import the contents from a tarball to create a filesystem image
docker import busybox.tar
When to use one over another?
In most cases, it wouldn't matter much.
However, from the perspective of running the command on an internet-enabled machine vs an air-gapped machine, there is a slight difference and you should really prefer to use
save and load combination.
Why? Because on an air-gapped machine, you might the full history/layers to load successfully, otherwise, you may encounter errors where there are missing layers/images. From my very very vague memory, the digest seems to be the same whether you run
load or import.