Shyla
Shyla

Reputation: 1

How to view netstat of a container within another container?

I want to view the network connections of a container in another container where my test scripts are running. I am using netstat or lsof, but unable to list connections of other container. Any pointers?

Upvotes: 0

Views: 649

Answers (1)

BMitch
BMitch

Reputation: 263469

You can connect to the namespace of another container with various options. For the network namespace, the option is --net container:$container_id as part of your docker run command:

$ docker run -d --name=nginx nginx
fcf8f1893ed8ff3b830665a85de8ab3dac471927784f666eee2d15522f154464

$ docker run -it --rm --pid container:nginx --net container:nginx nicolaka/netshoot netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      1/nginx: master pro

Upvotes: 1

Related Questions