Find Docker container info from PID

Jbn1233
Apr 4, 2021

Some of my cluster still running on Docker and this is how.

I wanted to know what is PID 25893 belongs to.

$ ./pidInfo.sh  25893
[
{
...
...
...
"Labels": {
"annotation.kubernetes.io/config.seen": "2021-03-23T11:40:30.983086928+08:00",
"annotation.kubernetes.io/config.source": "api",
"app": "elasticsearch-master",
"chart": "elasticsearch",
"controller-revision-hash": "elasticsearch-master-75b6469f4b",
"io.kubernetes.container.name": "POD",
"io.kubernetes.docker.type": "podsandbox",
"io.kubernetes.pod.name": "elasticsearch-master-1",
"io.kubernetes.pod.namespace": "client-stat-ts",
"io.kubernetes.pod.uid": "fcadf0c6-b5c9-411a-bd8b-7718a74e187e",
"release": "elasticsearch",
"statefulset.kubernetes.io/pod-name": "elasticsearch-master-1"
},
},
...
...
...

Yes it’s elasticsearch-master node.

cat podInfo.sh

#!/bin/bashCID=$(grep hostname /proc/$1/mountinfo |awk {'print $4'}|awk -F / {'print $3'})
docker inspect $CID

That is all.

--

--

Jbn1233

Very short and simple notes for CKA/SRE and may not works on your environment | jbn1233@gmail.com | Bangkok, Thailand |