Skip to content

Instantly share code, notes, and snippets.

@usrbinkat
Last active March 17, 2021 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save usrbinkat/185881014f1ec48b31f0546fa59f96ba to your computer and use it in GitHub Desktop.
Save usrbinkat/185881014f1ec48b31f0546fa59f96ba to your computer and use it in GitHub Desktop.
Exercise in container image saving, loading from file, and embedding as compressed base64 encoded text string

Container image file and transportation

Conclusion:

Images can be saved to file or base64 encoded for building directly into golang binaries, python/bash scripts, and carrying independently across disconnected systems.

Unfortunately, the only way to preserve image metadata is to save as a docker-archive transport type, and to podman load the resulting archive via following step:

cat pause-3.2.tar | podman load
cat registry-latest.tar | podman load

Save images as transport type tar file docker-archive and load from docker-archive tar file

podman image prune --all --force && podman images
skopeo copy --additional-tag docker.io/library/registry:latest docker://docker.io/library/registry:latest docker-archive://$(pwd)/registry-latest.tar
skopeo copy --additional-tag k8s.gcr.io/pause:3.2 docker://k8s.gcr.io/pause:3.2 docker-archive://$(pwd)/pause-3.2.tar
skopeo copy --additional-tag docker.io/library/registry:latest docker-archive://$(pwd)/registry-latest.tar containers-storage:docker.io/library/registry:latest
skopeo copy --additional-tag k8s.gcr.io/pause:3.2 docker-archive://$(pwd)/pause-3.2.tar containers-storage:k8s.gcr.io/pause:3.2

Save images as transport type tar file oci-archive and load from oci-archive tar file

podman image prune --all --force && podman images
skopeo copy --additional-tag docker.io/library/registry:latest docker://docker.io/library/registry:latest oci-archive://$(pwd)/registry-latest.tar
skopeo copy --additional-tag k8s.gcr.io/pause:3.2 docker://k8s.gcr.io/pause:3.2 oci-archive://$(pwd)/pause-3.2.tar
skopeo copy --additional-tag docker.io/library/registry:latest oci-archive://$(pwd)/registry-latest.tar containers-storage:docker.io/library/registry:latest
skopeo copy --additional-tag k8s.gcr.io/pause:3.2 oci-archive://$(pwd)/pause-3.2.tar containers-storage:k8s.gcr.io/pause:3.2

EXPERIMENTAL / MAD HAT SCIENCE

DISCLAIMER: this method requires bizzare handling of images and storage and cannot be expected to work at any given time in the future

Pull images

podman pull k8s.gcr.io/pause:3.2
podman pull docker.io/library/registry:latest

Save images as compressed base 64 encoded text strings

podman save k8s.gcr.io/pause:3.2 | xz -z9ec -T4 | base64 -w 0 > pause.tar.xz.txt
podman save docker.io/library/registry:latest | xz -z9ec -T4 | base64 -w 0 > registry.tar.xz.txt

Check files

kmorgan@mprcs:/tmp/test$ du -sh *
308K    pause.tar.xz.txt
9.2M    registry.tar.xz.txt

Remove all locally cached images

podman image prune --all --force
podman images

Load images from txt string

kmorgan@mprcs:/tmp/test$ base64 -d pause.tar.xz.txt | xz -dc | podman load --quiet
Loaded image(s): k8s.gcr.io/pause:latest
kmorgan@mprcs:/tmp/test$ base64 -d registry.tar.xz.txt | xz -dc | podman load --quiet
Loaded image(s): quay.io/cloudctl/registry:latest

Verify images are present

kmorgan@mprcs:/tmp/test$ podman images
REPOSITORY                  TAG     IMAGE ID      CREATED        SIZE
docker.io/library/registry  latest  5c4008a25e05  2 weeks ago    26.8 MB
k8s.gcr.io/pause            3.2     80d28bedfe5d  13 months ago  686 kB
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment