How to recover a docker image from Kubernetes Node
15 Feb 2025When you’ve lost a Docker image from your remote repository but it’s still cached on a Kubernetes Node, you can recover it using containerd’s command-line tool, ctr. This tool is typically bundled with containerd installations.
Using ctr
ctr, often included in containerd installations, can be used in conjunction with crictl, a standalone kubernetes-sigs project. Here’s how to interact with ctr and containerd:
-
Set up the environment: To interact with ctr define this environment variable:
export CONTAINER_RUNTIME_ENDPOINT="unix:///run/containerd/containerd.sock"
-
For basic authentication (e.g., with AWS ECR):
ECR_REGION=us-east-1 ECR_PASSWORD=$(aws ecr get-login-password --region $ECR_REGION)
-
Tagging and pushing images:
ctr -n k8s.io image tag <IMAGE> <ECR:IMAGE:TAG> ctr -n k8s.io image push --user "AWS:$ECR_PASSWORD" <ECR:IMAGE:TAG>
Note: The ‘k8s.io’ namespace is required for image interactions.
Other Helpful Tools
- nerdctrl: Docker-compatible CLI for containerd
- crictl: crictl provides a CLI for CRI-compatible container runtimes.
Your donations are appreciated. Thank you!