Skip to content

Instantly share code, notes, and snippets.

@jsidhu
Created October 6, 2017 18:39
Show Gist options
  • Save jsidhu/d6924f549df7f2f440a6e8af109f9d08 to your computer and use it in GitHub Desktop.
Save jsidhu/d6924f549df7f2f440a6e8af109f9d08 to your computer and use it in GitHub Desktop.

Revisions

  1. jsidhu created this gist Oct 6, 2017.
    16 changes: 16 additions & 0 deletions find_docker_container_from_pid.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    #!/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