Save vs. Export

Difficulty: Advanced

Question

What is the difference between docker save and docker export, and when would you use each (along with docker load and docker import)?

Answer

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.

Side by side

docker save / docker loaddocker export / docker import
Works onImages (by name, tag or ID)Containers (running or stopped)
LayersPreserved, one entry per layerFlattened into one filesystem
Image config (CMD, ENTRYPOINT, ENV, EXPOSE, USER)PreservedLost; must be re-added with import --change
HistoryPreservedLost
Container's runtime changesNot included (images only)Included (it is the container's current filesystem)
Volume dataNot includedNot included (mounts are outside the container filesystem)
Typical useAir-gapped deploys, offline transfer, backup of imagesInspecting 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.

When save and load are the right tool

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.

When export and import make sense

  • Grabbing the exact filesystem of a broken or compromised container for offline analysis.
  • Producing a flattened single-layer image, sometimes used to hide intermediate history. Note that flattening also discards layer sharing, so every pull downloads the whole thing again.
  • Creating a base image from a root filesystem tarball, such as a distro rootfs.

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.

Quick way to remember

Save is for images and keeps the recipe history; export is for containers and gives you just the contents of the box.

Shipping images to an air-gapped server. docker save and load keep every layer and setting, so the target runs exactly what CI tested.
  1. Build and scan in CI: Tag the release images, for example api:3.2.0.
  2. docker save into one archive: Bundle several images and compress the tar.
  3. Transfer the archive: SCP via a jump host or approved media.
  4. docker load on the target: Restores layers, tags, CMD and ENV.
  5. Run with the same tags: Compose or run scripts work unchanged.

Code examples

save and load for an offline server

# 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.

export and import lose the image config

# 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.

Key points

  • save/load works on images and preserves layers, tags, config and history.
  • export/import works on containers and produces a flat filesystem with no metadata.
  • Neither includes volume data.
  • Imported images need CMD, ENV and other settings re-added with --change.
  • Prefer a registry when one is reachable; it deduplicates layers.

Common follow-up questions

  • How would you back up the data in a named volume?
  • How do you deploy Docker images to a server with no internet access?
  • Why might a flattened image be worse for pull performance?
  • What does the OCI image layout contain?

Interview tips

  • Anchor the answer on image versus container; everything else follows from that.
  • Mention the missing CMD after import; it shows you have actually used the commands.
  • An air-gapped deployment example makes the answer concrete and practical.

Concepts covered

docker save, docker export, docker load, docker import, Air-gapped deployment

More Docker & Containers questions