Prefer Docker save and load

Advocate for better developer's productivity and experience
Documenting my learnings and sharing it
Search for a command to run...

Advocate for better developer's productivity and experience
Documenting my learnings and sharing it
No comments yet. Be the first to comment.
Background Recently, I redesigned my team's pipeline running on a multi-module Maven monorepo using GitLab CI. It wasn't that the previous setup was broken, but my team faced a few persistent issues t
Background At work, there’s some test written where I wanted to query the database (repository) after mockMvc request has been made to verify the result. This is a very simple illustration of what it looks like. @SpringBootTest @AutoConfigureMockMvc ...

It's been a long time coming, but I finally came around to set up MongoDB with replicas for local development. TLDR; clone the repository, run docker compose up -d, and you are good to go! If you want to know more, continue to read below. Context Run...

Context I recently came across TaskFile and wanted to use it to automate some of my workflows, which underlying invokes PowerShell commands. However, I faced several errors while doing so, and this post is to reflect on it, and hopefully help myself ...

Problem I was always out of disk space in my C drive, and even though I clear my stuff often, I notice that my space is never reclaimed, instead, it kept going down. I used WizTree to view which file is taking up my disk space, and I noticed this No...

over Docker export and import.
This serves as a reminder for me as I often mixed up myself.
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 restores the full history and layers from what was saved
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 exported content
Import the contents from a tarball to create a filesystem image
docker import busybox.tar
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.
References: