title: Docker - Get bound port inside java application
body: <p>I am creating a instance of my image like</p>
  
  <pre><code>docker run -P webmodule-xy
  </code></pre>
  
  <p>The Dockerfile for the webmodule exposes a port (e.g. 8080).</p>
  
  <p>My goal now is to obtain the mapped / assigned port number which is accessible from the outside via Java. Is there a environment variable or something like that?</p>
  
  <p>Usecase: 
  The webmodule-xy should register itself on another web-application and provide its IP + Port so the other application can contact the webmodule-xy later on. IP is no problem, but the port is.</p>
  
  <p>I already found this <a href="https://github.com/docker/docker/issues/3778" rel="noreferrer">open issue</a> on GitHub, but I can't believe that there is no simple solution. Like stated there, REST is not an option:</p>
  
  <blockquote>
    <p>Allowing a container to have access to the REST API is problematic.
    For one thing, the REST API is read/write, and if all you need is to
    read your portmappings, that's a dangerous level of permissions to
    grant a container just to find out a few ports.</p>
  </blockquote>