Skip to content

Instantly share code, notes, and snippets.

@gyermolenko
Created April 21, 2017 15:26
Show Gist options
  • Save gyermolenko/14fcdae3f6ca0d649e8717fbeb5a8819 to your computer and use it in GitHub Desktop.
Save gyermolenko/14fcdae3f6ca0d649e8717fbeb5a8819 to your computer and use it in GitHub Desktop.
Kill process in running docker container by its name
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