-
-
Save qjawe/d693bb4e177ca5e7a1035858ced01711 to your computer and use it in GitHub Desktop.
Enter a running docker container
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/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 |
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
_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