$linuxjunkies
>

nsenter(1)

Run a program in a namespace context by entering the namespaces of another process.

UbuntuDebianFedoraArch

Synopsis

nsenter [OPTION]... [PROG [ARGS]...]

Description

nsenter enters one or more namespaces of an existing process and then executes a program. This is useful for inspecting and interacting with containers, as each container typically has its own set of namespaces (network, PID, IPC, mount, UTS, user).

Common uses include debugging running containers, accessing container filesystems, or running commands within an existing container's namespace context without needing to exec through the container runtime.

Common options

FlagWhat it does
-t PIDEnter namespaces of the specified process (most common usage)
-n, --netEnter the network namespace
-p, --pidEnter the PID (process) namespace
-m, --mountEnter the mount namespace
-i, --ipcEnter the IPC namespace
-u, --utsEnter the UTS namespace (hostname/domainname)
-U, --userEnter the user namespace
-a, --allEnter all available namespaces
--root=PATHSet the root directory for the new process
--wd=PATHSet the working directory for the new process

Examples

Enter all namespaces of process 1234 and start a bash shell

nsenter -t 1234 /bin/bash

View network interfaces from process 1234's network namespace

nsenter -t 1234 -n ip addr

List the root directory as seen from process 1234's mount namespace

nsenter -t 1234 -m ls /

View network connections inside a running Docker container

docker inspect -f '{{.State.Pid}}' mycontainer | xargs -I {} nsenter -t {} -n netstat -an

List processes visible from process 1234's PID namespace

nsenter -t 1234 -p ps aux

Show IPC resources from process 1234's IPC namespace

nsenter -t 1234 -i ipcs

Related commands