Last active
November 17, 2015 02:59
-
-
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 )
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
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