Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find open sockets in docker container

Tags:

docker

I have attached to a docker container and need to find out the number of sockets being open by java application . Unfortunately there is no lsof or netstat available in the container . There is no data in /proc/PID/net/tcp. Is there any way I can find this data?

like image 813
Saril Sudhakaran Avatar asked Dec 01 '25 11:12

Saril Sudhakaran


1 Answers

I like netshoot for this. You can run a container in the same networking and even pid namespace, and use the tools in netshoot to analyze the other container's network:

$ docker run -d -p 8888:80 --name nginx-test nginx
d8a90f5c7d1744483ae6d26cc97dad222ed237b5c4211f711c9f15f88252897f

$ docker run --net container:nginx-test --pid container:nginx-test -it --rm nicolaka/netshoot

/ # netstat -lntp
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
/ # ps -ef
PID   USER     TIME   COMMAND
    1 root       0:00 nginx: master process nginx -g daemon off;
    7 104        0:00 nginx: worker process
    8 root       0:00 sh
   15 root       0:00 ps -ef
like image 81
BMitch Avatar answered Dec 03 '25 00:12

BMitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!