Skip to content

Instantly share code, notes, and snippets.

@euank
Created February 2, 2017 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euank/c49be5652decf9b165c719a16c7da540 to your computer and use it in GitHub Desktop.
Save euank/c49be5652decf9b165c719a16c7da540 to your computer and use it in GitHub Desktop.
pid=${1:?must provide pid argument}
function getMntns() {
ls -ali /proc/$1/ns/mnt | sed 's/.*mnt:\[\([0-9]\+\)\].*/\1/'
}
targetns=$(getMntns $pid)
for container in $(docker inspect --format '{{.State.Pid }}-{{ .Id }}' $(docker ps -q)); do
cpid=$(echo $container | awk -F- '{print $1}')
mntns=$(getMntns $cpid)
if [[ "${mntns}" == "${targetns}" ]]; then
echo "Found container id: $(echo $container | awk -F- '{print $2}')"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment