Sharing Container Images using the Docker CLI or Carvel's imgpkg
One thing I really appreciate in my current role at VMware, is being involved in great and often challenging customer engagements. Challenging is good! Because it often includes the opportunity to learn something new, based on the challenge you are facing. During my recent engagements with customers, I had to deal a lot with fully air-gapped environments, where even the jumphost we used had no internet connection.
In terms of Kubernetes (K8s) based deployments, where all the container image specifications are referencing to public repositories, you consequently have to make the necessary images offline, in a private registry, available before handing them over to K8s.
I’ve scratched this topic already in my recent post Deploy VMware Tanzu Packages from a private Container Registry, where I used the Carvel tool imgpkg
to download image bundles from a public registry, pack those into a tarball and to ultimately upload it to a private registry.
I also just learned (never had to use it before), that the docker
cli supports a similar method to save
one or more images into a tarball and to load
the tarball as a docker image locally again. Even though, imgpkg
supports a couple of more useful commands and options to handle image sharing and image relocating.
I’d like to cover both ways briefly in this post. I think it’s good to know these functionalities and have them in your repertoire.
I’ll start with the Docker CLI commands save
and load
first and will end this post with the imgpkg
tool.
Using Docker
I won’t cover docker export
and docker import
in this post! But in case you come across this, the TL;DR is:
A Docker image, which is built from a Dockerfile
, is like a template which includes the specifications for layers to build and run your application. Docker save
and load
only works with Docker images, while docker export
and docker import
will only be used to e.g. export a snapshot of the container’s filesystem.
docker save
The Docker CLI is giving you the following information when you “ask” for --help
.
|
|
There’s no real explanation necessary. You only have to specify the output file name and extension (.tar
) using the option -o
.
|
|
docker load
Now that the image is available in a shareable format, share it, so it can be loaded on the appropriate location using docker load
.
|
|
The following output is only to proof that no images were locally available on my 💻 when I was working on this example 😉
|
|
Having that proofed, let’s load the packed image using the option -i
:
|
|
<
and >
would work the same way for docker save (>)
and docker load (<)
Example:
|
|
Making it locally available is obvisouly just the step before finally pushing it to a private registry, to ultimately have it accessible for others as well.
|
|
And there we have it.
Flowchart Docker
Summarizing the above described steps:
Using imgpkg
Out of the great Carvel toolbox, which tools supports you in making your life easier in terms of application building, configurations and deployments to Kubernetes, imgpkg
offers some pretty neat commands to handle packaging, distributing, and relocating OCI images.
For now, we’re just taking a closer look on the imgpkg copy
command.
|
|
imgpkg copy --to-tar
Even if the two tools cannot be compared in detail with each other, they serve the same purpose for our intention. Even though, keep in mind that imgpkg
in contrast to the docker
CLI commands was build for such purposes and therefore it provides comprehensive capabilities and a really comfortable way of copying/relocating images.
The command imgpkg copy -i
downloads the desired container image from a registry and copies it to a local tarball.
|
|
This file can now be uploaded to e.g. a private registry using the option --to-repo
. If your repository is configured as private, so that authentication is required, the copy
command offers various options to support this case too.
Options are e.g. --registry-ca-cert-path
, --registry-username
and --registry-password
.
|
|
imgpkg copy --to-repo
The example above demonstrates how to copy an image, packed as a tarball, to a private repository using the option --to-tar
. You could also use the option --to-repo
which makes it even easier to relocate images from e.g. a public registry to a private one.
|
|
That’s awesome!
Flowchart imgpkg
Summarizing the steps using imgpkg
.
That simple! 😄
Resources
- Carvel Docs - imgpkg
- Docker Docs - docker save
Blogpost cover by pixabay