How to find the container image path based on pod name or container ID

9/20/2018

Let's say I have a 3 node cluster (master01, node01, node02)

How can I find the running container path on node? I can see container ID by "oc describe pod"

Container ID:   docker://9982c309a3fd8c336c98201eff53a830a1c56a4cf94c2861c52656855cba3558

eg: on node 01, I can see a lot of directories under "/var/lib/openshift/openshift.local.volumes/pods/"; but not sure how this map to pod names or container names. Seems inactive container maps/mounts but how to do a sage clean up ?

Any help really appreciated. Thank you.

-- Gineesh
containers
docker
kubernetes
openshift

3 Answers

9/20/2018

You can use this to list the container image by pod name:

kubectl get pods POD_NAME -o=jsonpath='{..image}'

Source: Docs

-- Bernardo Siqueira
Source: StackOverflow

9/20/2018

Generally, all the container filesystems + images live under your docker home directory which defaults to /var/lib/docker. You can also see if it has been custom configured by looking at the current dockerd process:

ps -Af | grep dockerd

Since you are running docker as your runtime. You can use to clean up all the garbage:

docker system prune -a --force

Basically, it prunes all the exited containers and the images that are not being used by any container.

Hope it helps!

-- Rico
Source: StackOverflow

9/20/2018

Thanks for your answers.

I have found it from another group and given below.

Method 1:

kubectl get pods <pod name> -o jsonpath={.metadata.uid}

Then look up the uid returned in /var/lib/kubelet/pods/<uid> (or /var/lib/openshift/pods/<uid>) on the node where the pod is located.

Methods 2:

kubectl describe pod <podname>

Get the container id from there.

Then run a docker inspect <containerid> on the node

Then look up the uid returned in /var/lib/kubelet/pods/<uid> (or /var/lib/openshift/pods/<uid>) on the node where the pod is located.

-- Gineesh
Source: StackOverflow