Difficulty: Advanced
What is the difference between docker save and docker export, and when would you use each (along with docker load and docker import)?
docker save packages one or more images into a tar archive with all their layers, tags and metadata (CMD, ENV, history), and docker load restores them exactly. docker export dumps a container's filesystem as a single flat tar with no layers, no history and no image config, and docker import turns such a tarball into a new one-layer image. Use save/load to move images between machines; use export only when you want a plain filesystem snapshot.
docker save / docker load | docker export / docker import | |
|---|---|---|
| Works on | Images (by name, tag or ID) | Containers (running or stopped) |
| Layers | Preserved, one entry per layer | Flattened into one filesystem |
Image config (CMD, ENTRYPOINT, ENV, EXPOSE, USER) | Preserved | Lost; must be re-added with import --change |
| History | Preserved | Lost |
| Container's runtime changes | Not included (images only) | Included (it is the container's current filesystem) |
| Volume data | Not included | Not included (mounts are outside the container filesystem) |
| Typical use | Air-gapped deploys, offline transfer, backup of images | Inspecting or migrating a filesystem, building a base from a rootfs |
Since Docker Engine 25, the archive written by docker save follows the OCI image layout (while keeping the legacy Docker manifest for compatibility), so other OCI tools can read it.
Many banks, government projects and on-premise enterprise installs run servers with no internet or registry access. The usual flow is: build and scan in CI, docker save the release images into one archive, copy it across (SCP, a jump host, sometimes physical media), then docker load on the target. Because layers are preserved, the image behaves exactly like the one you tested. Compress with gzip or zstd; docker load accepts gzip, bzip2, xz and zstd compressed archives.
Where a registry is reachable, prefer docker push and docker pull. Registries deduplicate layers and transfer only what is missing, while a saved tar always contains every layer.
The big gotcha: an imported image has no CMD or ENTRYPOINT, so docker run on it fails with "no command specified" unless you pass a command or add --change 'CMD ["nginx", "-g", "daemon off;"]' during import. Environment variables, exposed ports and the working directory are gone too.
Save is for images and keeps the recipe history; export is for containers and gives you just the contents of the box.
# On the build machine: bundle and compress two images
docker save api:3.2.0 worker:3.2.0 | gzip > release-3.2.0.tar.gz
# Copy it over (through a jump host, for example)
scp release-3.2.0.tar.gz deploy@10.0.4.12:/opt/releases/
# On the air-gapped server
docker load -i /opt/releases/release-3.2.0.tar.gz
docker image ls api
One archive can carry several images; load restores their tags and full configuration.
# Flatten a container's current filesystem
docker export web > web-rootfs.tar
# Import as a new single-layer image; CMD must be re-added
docker import \
--change 'CMD ["nginx", "-g", "daemon off;"]' \
--change 'EXPOSE 80' \
web-rootfs.tar web-flat:1
docker history web-flat:1
The imported image has a single layer and no history. Without --change it would have no CMD and fail to start.
docker save, docker export, docker load, docker import, Air-gapped deployment