brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: lsns lists the Linux namespaces on a host, including those of your containers

Linux
~/tips/tip-linux-lsns-namespaces

sudo lsns -t net

Lists namespaces and the processes in them, which shows how containers are separated.

Containers are mostly namespaces: a process gets its own view of the network, mounts, process IDs and so on. lsns lets you see them from the host.

sudo lsns -t net

-t picks the type: mnt, net, ipc, user, pid, uts, cgroup or time, and you can give it more than once. With -t net, each Docker container on its own network shows up as a separate network namespace with the process that holds it.

To see which namespaces one process lives in:

sudo lsns -p 1234

Comparing that with lsns -p 1 shows at a glance which namespaces a container shares with the host and which are its own.

For scripts, the man page recommends setting the columns yourself with --output, since the default output can change between versions. -H lists the columns you can pick.

Caveats. Without root the list is incomplete, so use sudo. A namespace that has no process left in it does not show up. And with -t net some cells span several lines; -W keeps each entry on one line.

Further reading: lsns manual

More Linux tips a2query -m rewrite renice -n 10 -p 4242 cat config.yml | xsel -ib xvfb-run -a your-program --some-flag dpkg --get-selections > packages.txt All Linux tips (261) All topics

Link