xwbraq
Last Updated: February 25, 2016
·
8.366K
· chrismckinnel

Attach to your Docker containers with ease using nsenter

Using nsenter you can enter your docker containers and inspect what is going on inside:

sudo nsenter -t $(docker inspect --format '{{ .State.Pid }}' $(docker ps -lq)) -m -u -i -n -p -w

The above will enter you into the latest running container on your host.

$(docker inspect --format '{{ .State.Pid }}' [container_id])

This returns the PID of the specified container which we pass into the -t option of nsenter by formatting the JSON output of docker inspect.

$(docker ps -lq)

This returns the container ID of the last running container (-q means only container ID and -l means lastest).