Query port number used by process in a docker container
I have 2 docker containers – one running a monitoring app and the other running a service, both running in the same network namespace with net=host. (Mesos runs all jobs with this parameter.)
The service can bind to a random port.
How can I query which port has the service bound itself to, from the monitoring container?
I tried reading /proc/net/tcp, but that seems to be very complex. Is there an easier way to do it?
2 Solutions collect form web for “Query port number used by process in a docker container”
So, if I understand correctly, the service binds to random ports? If so, why is that the case? I guess this is far from ideal, all services I use bin to a specific port when used in a container.
For example, if you have an app (started via Marathon) which binds to a port defined via an environment variable, you could set this environment variable when you start the container, and use the
BRIDGED networking mode to let Mesos choose a port from its port range.
If you install Mesos DNS, you could use it to determine the IP/port combination from the application name. E.g. if the Marathon app name is testapp, the service name will be
link for this:
docker run --name myService service docker run --link myService monitoring
more info you can find here https://docs.docker.com/engine/userguide/networking/default_network/dockerlinks/