Created
October 6, 2017 18:39
-
-
Save jsidhu/d6924f549df7f2f440a6e8af109f9d08 to your computer and use it in GitHub Desktop.
shell script to find docker container from process id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cpid=$1 | |
while true; do | |
ppid=$(ps -o ppid= -p $cpid) | |
pname=$(ps -o comm= -p $ppid) | |
if [ "$pname" == "docker" ]; then | |
echo "$cpid parent $ppid ($pname)" | |
break | |
else | |
echo "$cpid parent $ppid ($pname)" | |
cpid=$ppid | |
fi | |
done | |
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Name}}' | grep $cpid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Same using containerd instead of docker: