title: Get exposed port number (and address) from inside docker container
body: <p>I have code running inside a docker container. This needs to know where it is exposed on the network (address and port).</p>
  <p>This a duplicate of <a href="https://stackoverflow.com/questions/51784180/ho-to-determine-docker-container-port-number/51785358">this question</a> but 1) that was unanswered and 2) I'm asking about the generic case of how to programmatically find the values - not specifically a particular language.</p>
  <p>(please don't tell me to run a command on the manager after the container is started - that's NOT what I'm asking).</p>
  <p>I want code running inside my docker instance to know where the container is exposed on the real network. I can get the IP address it is using simply by calling a service across the network, but I also need to know the port number(s) it is using.</p>
  <p>I see that other people have solved the problem by using fixed ports and <a href="https://www.cloudbees.com/blog/connecting-docker-containers-to-production-network-ip-per-container" rel="nofollow noreferrer">assigning different IP addresses</a> to each instance. But this seems rather heavy on resources and dependencies.</p>
  <p>I also see that if I define a link at run time I can find the information about <em>other</em> containers on the same controller but not about the container where the code is running.</p>