Skip to content

Instantly share code, notes, and snippets.

@rhuss
Last active August 29, 2015 14:05
Show Gist options
  • Save rhuss/a8a40bd143001fd5c83c to your computer and use it in GitHub Desktop.
Save rhuss/a8a40bd143001fd5c83c to your computer and use it in GitHub Desktop.
nsenter with boot2docker
#!/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 $@
_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
@rhuss
Copy link
Author

rhuss commented Sep 1, 2014

See also this Blog Post

@rhuss
Copy link
Author

rhuss commented Sep 1, 2014

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)

@rhuss
Copy link
Author

rhuss commented Sep 1, 2014

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