Docker save cherry pick two tags

I need to run docker in a server without network. So I need to use docker save to save the whole image to a tar file and copy it to the server. That’s fine.

But Every time I add new tools to my image, I have to use docker save the very large tar file and copy it. It’s very time consuming to save and copy.

Then I find there is a cherry pick version in the document(docker save | Docker Documentation). But it seems the diff version is very large. Here are my steps:

  1. docker run -it lili/transformers:v3 bash
  2. install some tools by apt install
  3. docker commit this container as lili/transformers:v4
  4. docker save -o diff.tar lili/transformers:v3 lili/transformers:v4

$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
lili/transformers v4 98f22a3d0d02 32 minutes ago 12.8GB
lili/transformers v3 659eb3fa2163 26 hours ago 12.8GB

$ docker history lili/transformers:v4
IMAGE CREATED CREATED BY SIZE COMMENT
98f22a3d0d02 54 minutes ago bash 1.53MB
659eb3fa2163 27 hours ago bash 37.2MB
64acb2d9c6e3 27 hours ago bash 202MB
5221c70a1353 7 days ago bash 5.59GB
fa7573004516 2 months ago RUN |1 TARGETARCH=amd64 /bin/sh -c apt-get u… 2.82GB buildkit.dockerfile.v0
2 months ago LABEL com.nvidia.cudnn.version=8.1.1.33 0B buildkit.dockerfile.v0

du -sh diff.tar
12G diff.tar

It seems the cherry pick version’s size is not smaller as I expected.

anyone could help? Or does nay other work around for my question?

May I ask what makes you expect that the size would be smaller?

With docker save the metadata of the image, the tag points to, and every image layer it consists of are saved. If you save a single image the only way to bring the size down is a) optimize your image to be smaller and b) use gzip (or even better pigz) to create a tar.gz instead of an uncompress tar archive.

You do benefit from image layer de-dupplication if you save multiple tags at once that share the same parent images. There is no cherry picking of image layers in vanilla docker.

Though there is a docker fork, designed for embedded system that indeed creates image that only contain the diff from one tag to another. Someone posted it in the forum, but I don’t recall the name (update: see balenaEngine - A container engine purpose-built for IoT devices)