Run tcpdump in a container netns from the host

Capture container traffic with the host's tcpdump through its netns. The image needs no extra tools

PID=$(docker inspect -f '{{.State.Pid}}' <name>); nsenter -t $PID -n tcpdump -ni any -c 50

tool
namespaces4 commands
tags
namespacesnetworkdebugtroubleshooting

More namespaces commands

  • nsenter -t $(pgrep -n <proc>) -n -m -p ss -tlnp

    Enter the net, mount and pid namespaces of the newest matching process and list the listening sockets it sees

  • unshare --net --pid --fork --mount-proc bash # then: ip netns add test; ip netns exec test ip a

    Start a shell in new net and pid namespaces with its own /proc. Use ip netns to test named netns

  • lsns -p <pid>; readlink /proc/<pid>/ns/net /proc/1/ns/net # equal inode = same netns

    List all namespaces of a PID. If two ns links have the same inode, the namespace is shared

all 4 namespaces commands