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?

  • No Space on CentOS with Docker
  • Connect to a Service running inside a docker container from outside
  • host to docker directory mount error
  • kairosdb service not starting in container
  • Connecting Docker container to corporate LDAP server through SSL
  • How to attach visual studio 2015 debugger to previously deployed asp.net core docker container
  • I tried reading /proc/net/tcp, but that seems to be very complex. Is there an easier way to do it?

  • docker: how to do/setup networking container-to-host for udp / snmp
  • x509: certificate signed by unknown authority when building docker image
  • Docker port conflict on Ubuntu
  • Expose container port to Host using Docker for Windows in Windows 10
  • Project Atomic - Cockpit doesnt install through Vagrant
  • Port forwarding in Jelastic with Docker
  • 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 testapp.marathon.mesos.

    See

    Use 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/

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.