Skip to content

Instantly share code, notes, and snippets.

@qjawe
Forked from mschuerig/docker-enter
Created February 8, 2017 00:50
Show Gist options
  • Save qjawe/d693bb4e177ca5e7a1035858ced01711 to your computer and use it in GitHub Desktop.
Save qjawe/d693bb4e177ca5e7a1035858ced01711 to your computer and use it in GitHub Desktop.
Enter a running docker container
#! /bin/sh -e
# See
# http://blog.docker.com/2014/06/why-you-dont-need-to-run-sshd-in-docker/
# https://github.com/jpetazzo/nsenter
case "$1" in
-h|--help)
echo "Usage: docker-enter CONTAINER"
exit 0
;;
esac
if [ $(id -ru) -ne 0 ]; then
echo "You have to be root."
exit 1
fi
if [ $# -ne 1 ]; then
echo "Usage: docker-enter CONTAINER"
exit 1
fi
PID=$(docker inspect --format {{.State.Pid}} "$1")
nsenter --target $PID --mount --uts --ipc --net --pid
exit 0
_docker_enter() {
local cur prev words cword
_get_comp_words_by_ref -n : cur prev words cword
__docker_containers_running
}
complete -F _docker_enter docker-enter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment