Created
May 12, 2020 07:40
-
-
Save cl4u2/67438381d4fac2187563d9c30e6cc639 to your computer and use it in GitHub Desktop.
Find the Docker container running the process with the specified process ID (PID) (as seen from the Docker host)
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 | |
targetpid=$1 | |
parentpid=0 | |
while [ $parentpid != 1 ]; do | |
parentpid=$(ps -o ppid= $targetpid) | |
docker ps -q | xargs docker inspect --format '{{.State.Pid}}, {{.Name}}' | grep "^$parentpid" | |
targetpid="$parentpid" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment