Last Updated: February 25, 2016
· kytwb

How to enter and administrate any running Docker container


Same day I wrote this protip, Docker released 1.3 which introduces docker exec (see details). I leave this protip to show how the nsenter way.

Deprecated (see above)

Install nsenter by following these steps:

cd /tmp
curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz | tar -zxf-
cd util-linux-2.24
./configure --without-ncurses
make nsenter
cp nsenter /usr/local/bin

Then, just run this one-liner:

CONTAINER_ID=$(docker ps -a | grep <container_name> | awk '{print $1 }') && CONTAINER_PID=$(docker inspect --format "{{ .State.Pid }}" $CONTAINER_ID) && sudo nsenter --target $CONTAINER_PID --mount --uts --ipc --net --pid

Don't forget to replace <container_name> by the actual name of the Docker container you want to adminsitrate.

2 Responses
Add your response


You can also access to your container with docker exec command

$ docker ps
$ docker exec -it $CONTAINER_PID bash
over 1 year ago ·

I've updated the protip.

over 1 year ago ·