Skip to main content

Exporting and importing docker images manually

 


Why

Sometimes it can be handy to have a copy of a container image locally or being able to manually copy a docker image from one computer to another. 

Recently I had an issue where newly built Kubernetes worker nodes did not work properly due to the fact that the flannel pod image was hosted on quay.io, which was not available at the time. The "fix" was to manually export the image from a server which had flannel running just fine and import on the new worker nodes (and restart the flannel pods).

Export

Assuming we want to save / export the image below:

$ docker images
REPOSITORY     TAG       IMAGE ID       CREATED       SIZE
kindest/node   <none>    af39c553b6de   2 weeks ago   1.12GB

We run docker save with the image id and redirect the output into a new local file.

$ docker save af39c553b6de > kindest-node.tar

Once done, we end up with a new tar file, which can be compressed optionally.

$ ls -lah kindest-node.tar 
-rw-rw-r-- 1 user user 1.1G Jun  6 12:11 kindest-node.tar
$ file kindest-node.tar
kindest-node.tar: POSIX tar archive

$ time pigz kindest-node.tar
real 0m3.353s
user 0m44.956s
sys 0m1.693s

$ ls -lah kindest-node.tar.gz 
-rw-rw-r-- 1 user user 450M Jun  6 12:11 kindest-node.tar.gz

Then we can copy the file to a different computer and import the image.

Import

To import the image manually, run the following command:

$ cat kindest-node.tar.gz | gzip -d | docker load
fe4ff16afbd5: Loading layer [==================================================>]  81.79MB/81.79MB
5b0bb23616f6: Loading layer [==================================================>]  15.36kB/15.36kB
af7c97115567: Loading layer [==================================================>]  3.584kB/3.584kB
0b1209dd2b24: Loading layer [==================================================>]   25.6kB/25.6kB
b0841d5ea26b: Loading layer [==================================================>]   12.8kB/12.8kB
20f5bf344878: Loading layer [==================================================>]  4.096kB/4.096kB
9adb7beab274: Loading layer [==================================================>]  3.072kB/3.072kB
c4d2062b972b: Loading layer [==================================================>]  3.072kB/3.072kB
463693fedd13: Loading layer [==================================================>]   7.68kB/7.68kB
9981da0c28e6: Loading layer [==================================================>]   5.12kB/5.12kB
1d56cf6e0165: Loading layer [==================================================>]  217.7MB/217.7MB
d0261d0f10de: Loading layer [==================================================>]  824.1MB/824.1MB
Loaded image ID: sha256:af39c553b6deb8ad9c3fb94ee6b4afbe3f7501296cf7e2f20aa1f8a13494f24c

$ docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
<none>       <none>    af39c553b6de   2 weeks ago   1.12GB

$ docker tag af39c553b6de kindest/node:v1.21

$ docker images
REPOSITORY     TAG       IMAGE ID       CREATED       SIZE
kindest/node   v1.21.1   af39c553b6de   2 weeks ago   1.12GB

Voila, we have the image with correct tag on the new server ready to use.

Conclusion

While you should keep your Docker container images in your own container registry or proxy / cache external registries wherever you can it can be quite handy to know how to manually keep copies of your images or move them from one Docker runtime to another.

I have now set up a local Docker registry image proxy for quay.io, so this issue will hopefully not be repeated.



Comments

Popular posts from this blog

Manual Kubernetes TLS certificate renewal procedure

Intro Kubernetes utilizes TLS certificates to secure different levels of internal and external cluster communication.  This includes internal services like the apiserver, kubelet, scheduler and controller-manager etc. These TLS certificates are created during the initial cluster installation and are usually valid for 12 months. The cluster internal certificate authority (CA) certificate is valid for ten years. There are options available to automate certificate renewals, but they are not always utilised and these certs can become out of date. Updating certain certificates may require restarts of K8s components, which may not be fully automated either. If any of these certificates is outdated or expired, it will stop parts or all of your cluster from functioning correctly. Obviously this scenario should be avoided - especially in production environments. This blog entry focuses on manual renewals / re-creation of Kubernetes certificates. For example, the api-server certificate below...

Enhancing Kubernetes Security: Enabling API Server Audit Logging

      In the ever-evolving landscape of container orchestration and management, Kubernetes remains at the forefront, empowering organizations to deploy, manage, and scale their containerized applications efficiently. However, as Kubernetes environments grow in complexity, ensuring robust security measures becomes paramount. One crucial aspect of Kubernetes security is audit logging, particularly concerning the Kubernetes API server, which serves as the primary point of interaction with the cluster. The Importance of Audit Logging Audit logging provides visibility into the activities and interactions within a Kubernetes cluster. By recording requests and responses made to the API server, audit logs offer valuable insights into user actions, system modifications, and potential security breaches. This transparency is essential for compliance with regulatory requirements such as HIPAA, GDPR, and PCI DSS, as well as for detecting and investigating security incidents. Understan...

Choosing the Right Operating System for Kubernetes

  In the realm of container orchestration, Kubernetes reigns supreme as the de facto standard. It's the go-to platform for managing containerized applications at scale. However, as you delve into the world of Kubernetes deployment, one crucial decision often overlooked is the choice of operating system (OS). While Kubernetes itself is platform-agnostic, the underlying OS can significantly impact performance, security, and overall manageability. In this guide, we'll explore various operating systems suitable for Kubernetes deployment and help you make an informed decision. 1. Linux Distributions: a. Ubuntu: Pros: Ubuntu is one of the most popular choices for Kubernetes deployment due to its widespread adoption and strong community support. It offers a balance between stability and cutting-edge features. Cons: Some argue that Ubuntu's release cycle may introduce instability, especially for production environments requiring long-term support (LTS) versions. b. CentOS/RHEL: P...