Skip to content

Instantly share code, notes, and snippets.

@devopsy-ir
Last active May 22, 2023 01:53
Show Gist options
  • Save devopsy-ir/ba870f5d53990630943402bb45ce5c77 to your computer and use it in GitHub Desktop.
Save devopsy-ir/ba870f5d53990630943402bb45ce5c77 to your computer and use it in GitHub Desktop.
A Process to docker container mapper bash script
#!/bin/bash
processPath=$(find /proc/ -name $1 2>/dev/null | tail -1)
containerID=$(cat ${processPath}/cgroup | fgrep 'pids:/docker/')
if [ -n "$containerID" ];
then
containerID=$(echo $containerID | sed -e 's#.*/docker/##g' | cut -c 1-12)
docker ps | fgrep $containerID
else
echo 'Not a docker process!'
fi
@devopsy-ir
Copy link
Author

A simple script to obtain docker container name by it's process ID

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment