jrq1-g
Last Updated: February 25, 2016
·
522
· kytwb

How to enter and administrate any running Docker container

Update

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

17755

You can also access to your container with docker exec command

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

I've updated the protip.

over 1 year ago ·