Last active
March 21, 2017 05:54
-
-
Save WeiTang114/68f5e98f6c60421041e3538b35df8bfa to your computer and use it in GitHub Desktop.
Find container ID and name by a process name (or part of the command).
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 | |
DOCKERUSER='ns1-root' | |
KEY="$1" | |
function usage() { | |
echo "Usage: $0 <keyword>" | |
} | |
if [[ $# -lt 1 ]]; then | |
usage && exit -1 | |
fi | |
docker ps | tail -n +2 | \ | |
awk '{print $1 " " $NF}' | \ | |
xargs -I {} sh -c 'echo {}; p=`echo "{}"|cut -d " " -f 1`; docker top $p | grep '"$KEY" |\ | |
egrep "$DOCKERUSER" -B 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: