⚡ ~/naveed Interview Prep
⚡ Portfolio Home 👤 About Naveed Bio & Credentials 📫 Contact Naveed Get In Touch ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Docker & Containers Interview Questions Scenario 54 of 159 in Docker & Containers
Senior DevOps / SRE [L2] Docker Production Scenario [L2]
🎯 Target Role / Context: Docker Scenario #54 (L2) · Docker

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.

#Docker #L2 #Containers #Linux
🎙️ Candidate Opening & Architectural Context
"<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."
Advertisement
⚡ Recommended Practice Lab

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.

1️⃣

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: export dumps a container's flattened filesystem; import creates 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.
Pro Tip: Use save/load when you need to preserve the image as built. Use export only when you really want a flattened filesystem snapshot.
2️⃣

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.gz and gunzip -c my-app.tar.gz | docker load avoid writing an intermediate file.
  • Load: docker load -i my-app.tar prints Loaded image: ... for each tag restored.
  • Output to stdout: Without -o, docker save writes the tar stream to standard output and refuses to write to a terminal, so redirect or pipe it.
Advertisement
3️⃣

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.tar beside it and verify on the target before loading.
  • Compare image IDs: docker image inspect --format '{{.Id}}' my-app:1.4.2 should match on both hosts, since the image ID is the config digest.
  • Check the layers: docker history my-app:1.4.2 shows the build steps are preserved, unlike an imported container export.
  • Smoke test: Run docker run --rm my-app:1.4.2 --version or your health endpoint before promoting.
  • Inspect without loading: tar -tf my-app.tar lists manifest.json and the layer blobs, and tar -xOf my-app.tar manifest.json shows the tags stored in the archive.
4️⃣

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 error on another; verify docker 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.
5️⃣

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 offer kind load image-archive and minikube 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 load performs 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.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Pro-Tip: Save by name and tag, record a checksum with the archive, and push the loaded image into an internal registry so air-gapped clusters still pull through normal policy and scanning."
⚡ 60-Second Elevator Pitch Talking Points
  • 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.
⛔ Critical Candidate Mistakes to Avoid in This Scenario

Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:

  1. Using docker export when you meant docker save Export flattens a container and drops CMD, ENV and history, so the result behaves differently.
  2. Saving by image ID The loaded image has no repository or tag, which makes deployment and cleanup confusing.
  3. Loading archives from unknown sources docker load performs no signature or provenance check, so a malicious image runs as soon as it is started.
  4. Ignoring CPU architecture An amd64 archive loaded on an arm64 host fails at runtime with exec format error.
Advertisement
Want more Docker & Containers scenarios?
Explore our complete collection of scenario-based Docker & Containers interview runbooks.
Browse All Docker & Containers Questions →