title: How can I bind a port on one docker container to a port on a different docker container?
body: <p>I am trying to bind port 9000 on docker container 1 (A) to port 9000 on docker container 2 (B).</p>
  
  <p>I tried the <code>--net host</code> option but this does not help me. I need both containers to be on the same network (172.17.0.x) and have their ports bound similar to how the <code>-p port</code> flag is used to bind one container to the host. I have tried setting up listening ports on both A and B using the <code>--expose flag</code> but I have been unable to bind them.</p>
  
  <pre class="lang-sh prettyprint-override"><code>docker run -p 8080:8080\ # to bind port 8080 on A to port 8080 on the host
      -it -d \
      --cap-add NET_ADMIN \
      --cap-add NET_RAW \
      --expose 9000 \ # listening port to communicate with B
      &lt;image file&gt;
  
  docker run -p 8081:8081\ # to bind port 8081 on B to port 8081 on the host
      -it -d \
      --cap-add NET_ADMIN \
      --cap-add NET_RAW \
      --expose 9000 \ # listening port to communicate with B
      &lt;image file&gt;
  </code></pre>
  
  <p>I would like to map A's port 9000 to B's port 9000 (or any other port)
  Thanks!</p>