Created
April 21, 2017 15:26
-
-
Save gyermolenko/14fcdae3f6ca0d649e8717fbeb5a8819 to your computer and use it in GitHub Desktop.
Kill process in running docker container by its name
This file contains hidden or 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
dkill() { | |
# Example: | |
# $ dkill <container_name> <process_name> | |
if [[ $# -ne 2 ]] ; then | |
echo "dkill [container name] [process name]" | |
return 1 | |
fi | |
local pid=$(docker exec -it $1 ps aux | grep $2 | awk '{ print $2 }') | |
if [ -z "$pid" ] ; then | |
echo "process not found" | |
return 1 | |
else | |
docker exec -it $1 kill $pid | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment