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?

  • Error while running Jenkins in Docker
  • docker container exits immediately even with Console.ReadLine() in a .net core console application
  • Get containers running a given image version
  • accessing the docker container for rabbitmq from ubuntu host
  • Minimal configuration for Apache reverse proxy in Docker container
  • Get dockerfile / docker commands from docker image
  • I tried reading /proc/net/tcp, but that seems to be very complex. Is there an easier way to do it?

  • Python script with multiple rest queries fails when run in a docker container
  • mysql in docker container can't run through a mounted volume on os x
  • Docker and --userns-remap, how to manage volume permissions to share data between host and container?
  • dockerized nginx “times out” after several minutes
  • Allowing 'anyone' executable permission on /usr/local/bin/docker-compose?
  • Running VirtualBox in Ubuntu in Mac OSX, won't start up
  • 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.