nsenter

The nsenter tool is part of the util-linux package since version 2.23. It provides access to the namespace of another process. nsenter requires root privileges to work properly. Unfortunately, util-linux is still at version 2.20 in Ubuntu 14.04. To install the latest version (2.24) proceed as follows:

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

In order to connect to a container, you have to find out the PID of the first process in the container.

docker inspect --format "{{ .State.Pid }}" <container-id>

With that PID you can connect to the container:

nsenter --target $PID --mount --uts --ipc --net --pid
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐