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?

  • Dockers container image update
  • Swarm container not getting started with created overlay network
  • Docker container running but browser refuse to connect
  • Configure reverse-proxy for Keycloak docker with custom base URL
  • allow rabbitmq slave to join master
  • Invalid value while trying to create a kubernetes pod with secret in it
  • I tried reading /proc/net/tcp, but that seems to be very complex. Is there an easier way to do it?

  • my docker build just keeps closing
  • Docker using mysql
  • Xdebug ignores breakpoints in Netbeans for Php project created inside Docker container
  • Docker and UFW with real IP
  • Adding a new NIC to a Docker container in a specific order
  • How to setup docker to use cache from registry on every build step
  • 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.


    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.