Reputation: 63
I have following issue, I'm using kubernetes as k3d, when I apply new pods I need to import docker image for it, How can I check which images are imported to k3d ? When I was checking - I see only option to import image.
Upvotes: 5
Views: 1653
Reputation: 2278
There is not dedicated command to do it, but there is one way to achieve this
When you create k3d cluster with name mycluster
k3d cluster create mycluster --servers 1 --agents 1
You have to get running containers using docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
30d444e398b3 ghcr.io/k3d-io/k3d-proxy:5.6.0 "/bin/sh -c nginx-pr…" 3 minutes ago Up 3 minutes 80/tcp, 0.0.0.0:43607->6443/tcp k3d-mycluster-serverlb
ab845e460925 rancher/k3s:v1.27.4-k3s1 "/bin/k3s agent" 3 minutes ago Up 3 minutes k3d-mycluster-agent-0
f83045d927c7 rancher/k3s:v1.27.4-k3s1 "/bin/k3s server --t…" 3 minutes ago Up 3 minutes k3d-mycluster-server-0
Then take any server
or agent
node you want to check, I took k3d-mycluster-server-0
, and running command below will give you all images on that node
docker exec k3d-mycluster-server-0 crictl images
You should get clear output
IMAGE TAG IMAGE ID SIZE
docker.io/library/nginx alpine 529b5644c430c 44.4MB
docker.io/library/nginx latest a8758716bb6aa 191MB
docker.io/rancher/klipper-lb v0.4.4 af74bd845c4a8 4.92MB
docker.io/rancher/mirrored-library-traefik 2.9.10 d1e26b5f8193d 39.6MB
docker.io/rancher/mirrored-pause 3.6 6270bb605e12e 301kB
In my case I already imported 2 nginx images, rest are images required to run cluster node
If you want to grab all images across nodes you can run (some of them may exist only on one node) and it requires jq
installed
for x in $(docker ps --format json | jq ".Names" -r | grep -e '-server-' -e '-agent-'); do docker exec $x crictl images --output json | jq ".images[].repoTags[0]" -r; done | sort -u
Upvotes: 4