Skip to content

Instantly share code, notes, and snippets.

@cl4u2
Created May 12, 2020 07:40
Show Gist options
  • Save cl4u2/67438381d4fac2187563d9c30e6cc639 to your computer and use it in GitHub Desktop.
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)
#!/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