Skip to content

Instantly share code, notes, and snippets.

@xcsrz
Last active November 17, 2015 02:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xcsrz/1a9584a5069382d7301e to your computer and use it in GitHub Desktop.
Save xcsrz/1a9584a5069382d7301e to your computer and use it in GitHub Desktop.
A bash function to get inside a running docker container ... still needs tweaking, requires nsenter ( https://github.com/jpetazzo/nsenter )
getInside() {
# pass in a container ID
CONTID=$1;
# This prints out export commands you can paste into the terminal once inside the container - not always needed
sudo docker inspect $CONTID | awk '/(PATTERN FOR ENV VARIABLES YOU CARE ABOUT)/ { gsub(/[",]/,"",$1); print "export " $1 } '
# Get the process ID
PID=$(sudo docker inspect --format {{.State.Pid}} $CONTID );
# Status message
echo "Entering container $CONTID with PID $PID";
# Enter the container
sudo nsenter --target $PID --mount --uts --ipc --net --pid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment