Last active
May 22, 2023 01:53
-
-
Save devopsy-ir/ba870f5d53990630943402bb45ce5c77 to your computer and use it in GitHub Desktop.
A Process to docker container mapper bash script
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A simple script to obtain docker container name by it's process ID