Last active
August 29, 2015 14:05
-
-
Save rhuss/a8a40bd143001fd5c83c to your computer and use it in GitHub Desktop.
nsenter with boot2docker
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 | |
usage () | |
{ | |
cat <<EOF | |
docker-enter -- Enter a running container via boot2docker and nsenter | |
Usage: docker-enter <container_name_or_ID> [command] | |
See https://github.com/jpetazzo/nsenter for details. | |
EOF | |
} | |
if [ $# -eq 0 ] | |
then | |
usage | |
exit 1 | |
fi | |
boot2docker ssh 'which nsenter 2>&1 >/dev/null || sudo docker run --rm -v /usr/local/bin:/target jpetazzo/nsenter' | |
boot2docker ssh -t sudo docker-enter $@ |
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
_containers() | |
{ | |
_get_comp_words_by_ref -n : cur prev words cword | |
local containers="$(docker 2>/dev/null ps -q )" | |
local names="$(docker 2>/dev/null inspect --format '{{.Name}}' $containers | sed 's,^/,,')" | |
COMPREPLY=( $(compgen -W "$names $containers" -- "$cur") ) | |
} | |
complete -F _containers docker-enter |
Admittedly I missed the section about boot2docker at in nsenter's README ;-(. Updated the script accordingly. The value-add here is still the bash completion (which I found quite useful)
Copy docker_enter.sh
to $SOME_DIR_IN_PATH/docker_enter
and docker-enter_commands.sh
to ~/.bash_completion_scripts/
or /usr/local/etc/bash_completion.d
(or wherever you bash completion scripts are stored)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
See also this Blog Post