enter into running docker container

sometimes it is handy to enter into running docker container and to check some stuff while docker container is running. docker has handy tools to do that

we need first get PID of docker container we want to enter in

#docker inspect --format {{.State.Pid}} $(docker ps | grep | awk '{print $1 }')
replace in above command with name of your container

Once you have PID using nsenter you can enter into container

#nsenter -m -u -n -i -p -t $PID

meaning of particular nsenter parameters is listed below

# nsenter -h
Usage:
nsenter [options] [args...]
Options:
-t, --target target process to get namespaces from
-m, --mount [=] enter mount namespace
-u, --uts [=] enter UTS namespace (hostname etc)
-i, --ipc [=] enter System V IPC namespace
-n, --net [=] enter network namespace
-p, --pid [=] enter pid namespace
-r, --root [=] set the root directory
-w, --wd [=] set the working directory
-F, --no-fork do not fork before exec'ing
-h, --help display this help and exit
-V, --version output version information and exit
For more details see nsenter(1)

please note that nsenter is shipped as part ( at least on RHEL based distros ) on util-linux package

#rpm -qf $(which nsenter)
util-linux-2.23.2-21.el7.x86_64

Advertisements

#containers-nsenter, #docker-inspect