Get a shell into Docker container / Install nsenter

To get a shell into a Docker container without using ssh, install nsenter:

docker run -v /usr/local/bin:/target jpetazzo/nsenter

This installs nsenter in /usr/local/bin

And then save the script below as run_nsenter. To use it, do this:

run_nsenter <container name or id>
if [[ -z ${CONTAINER} ]]; then
echo "Usage: $0<container name or ID>"
exit 1

PID=$(docker inspect --format {{.State.Pid}} ${CONTAINER})
sudo nsenter --target $PID --mount --uts --ipc --net --pid

I found it easier to name the containers, alternatively you can run the script with container id. To check the container id, run this command:

docker ps -a

For detailed explanation, see:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s