Q: What does `docker save` and `docker load` do?
docker save writes one or more images, with all layers, tags and history, into a tar archive, and docker load reads that archive back into the local image store.
Want to master this scenario in a live sandbox? KodeKloud's Docker Certified Associate (DCA) Hands-On Lab Course covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: <strong><code>docker save</code> writes one or more images, with all layers, tags and history, into a tar archive, and <code>docker load</code> reads that archive back into the local image store.</strong> They are how you move images to air-gapped hosts, back up a build, or hand an image to a tool that cannot reach a registry. Interviewers ask this to see whether you can distinguish images from containers, and <code>save</code>/<code>load</code> from <code>export</code>/<code>import</code>, which flatten a container filesystem and drop image metadata.
Mental model: images versus containers
Save and load operate on images; export and import operate on containers.
- docker save: Packages the image layers, manifest, config and tags. The result keeps layer sharing, so saving several related images in one archive stores common layers once.
- docker load: Restores those layers and tags into the local daemon; images with the same layers are not duplicated.
- docker export / import:
exportdumps a container's flattened filesystem;importcreates a new single-layer image without CMD, ENTRYPOINT, ENV or history. - Not a registry: The archive is a transport format. It has no access control, no signature verification and no pull semantics.
- Typical use cases: Offline installs for secure networks, shipping a release to a customer environment, caching images between CI jobs, and preserving a build before a registry migration.
Hands-on: docker save and docker load
Create an archive, compress it, move it and load it on another host.
docker save -o stack.tar my-app:1.4.2 postgres:16
ls -lh stack.tar
# Transfer, then on the target host
scp stack.tar user@airgapped-host:/tmp/
docker load -i /tmp/stack.tar
# Loaded image: my-app:1.4.2
# Loaded image: postgres:16
# Stream over SSH without a temp file
docker save my-app:1.4.2 | gzip | ssh user@host 'gunzip | docker load'
- Save one image:
docker save -o my-app.tar registry.example.com/my-app:1.4.2. - Save several at once: Pass multiple image names to one command so shared base layers are stored once.
- Compress in a pipe:
docker save my-app:1.4.2 | gzip > my-app.tar.gzandgunzip -c my-app.tar.gz | docker loadavoid writing an intermediate file. - Load:
docker load -i my-app.tarprintsLoaded image: ...for each tag restored. - Output to stdout: Without
-o,docker savewrites the tar stream to standard output and refuses to write to a terminal, so redirect or pipe it.
Verify the image arrived intact
Confirm tags, image ID and checksums, because the archive travels outside registry integrity checks.
sha256sum my-app.tar
docker image inspect --format '{{.Id}}' my-app:1.4.2
docker images --digests | grep my-app
- Checksum the archive: Publish
sha256sum my-app.tarbeside it and verify on the target before loading. - Compare image IDs:
docker image inspect --format '{{.Id}}' my-app:1.4.2should match on both hosts, since the image ID is the config digest. - Check the layers:
docker history my-app:1.4.2shows the build steps are preserved, unlike an imported container export. - Smoke test: Run
docker run --rm my-app:1.4.2 --versionor your health endpoint before promoting. - Inspect without loading:
tar -tf my-app.tarlistsmanifest.jsonand the layer blobs, andtar -xOf my-app.tar manifest.jsonshows the tags stored in the archive.
Failure modes and edge cases
Archives behave differently from registry pulls in a few important ways.
- Saved by ID loses tags: If you save using an image ID rather than a name, the loaded image has no tag and shows as
<none>; always save by name:tag. - Registry digest is not preserved: The registry manifest digest used by
image@sha256:...references can differ after load, so do not use load as proof of the registry artifact. - Platform mismatch: An archive built for one architecture will fail with
exec format erroron another; verifydocker image inspect --format '{{.Architecture}}'. - Large archives: Images with big layers produce huge tar files; check disk space on both ends and prefer a local registry when you transfer repeatedly.
- Daemon storage backend: Behaviour with multi-platform images can depend on whether the classic or the containerd image store is enabled in your Docker version, so test the round trip before relying on it.
Production practice and security
Treat the archive as an untrusted artifact until proven otherwise.
- Kubernetes nodes: To preload an image for containerd run
ctr -n k8s.io images import my-app.tar; kind and minikube offerkind load image-archiveandminikube image load. - Air-gapped mirrors: Prefer pushing to an internal registry after loading, so nodes pull normally and policy checks still apply.
- Supply chain: Scan the image after load with your scanner and verify signatures before transfer, because
docker loadperforms no signature check. - Retention: Store archives with the build ID and checksum in your artifact repository so disaster recovery does not depend on a single registry.
- CI caching: Saving an image to a CI cache works for small bases, but registry-backed BuildKit cache (
--cache-to type=registry) is usually faster and avoids multi-gigabyte tar files.
- docker save serializes images with layers, tags and history into a tar archive; docker load restores them into the daemon.
- I verify with sha256sum on the archive, matching image IDs on both hosts and a smoke run before use.
- I avoid ad hoc archives by pushing to an internal registry, and keep export/import only for container filesystem snapshots.
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Using docker export when you meant docker save Export flattens a container and drops CMD, ENV and history, so the result behaves differently.
- Saving by image ID The loaded image has no repository or tag, which makes deployment and cleanup confusing.
- Loading archives from unknown sources docker load performs no signature or provenance check, so a malicious image runs as soon as it is started.
- Ignoring CPU architecture An amd64 archive loaded on an arm64 host fails at runtime with exec format error.