Answers: <p>If you have a <a href="https://docs.docker.com/v17.09/engine/userguide/networking/#user-defined-networks" rel="nofollow noreferrer">user-defined network</a> set to bridge, you can access other containers by their container's name which is automatically as hostname for containers inside same network.</p>
  
  <p>So from <code>containerA</code> you could do <code>ping containerB</code> without problems. In your case it would be changing the setting to <code>containerB_name:(container B needed port)/route</code></p>
  
Answers: CC BY-SA 4.0
Answers: 2018-12-28T19:10:19.120Z
Answers: 2018-12-28T19:10:19.120Z
Answers: Alberto Castillo G
Body: <ul>
  <li>I have two docker containers A and B that runs on the same user-defined network.</li>
  <li><p>Container A has a port published, container B hasnt.</p></li>
  <li><p>I do my requests on container's A published port, but container A needs to do requests on container B.</p></li>
  <li><p>The requests to B inside A are mapped to <code>0.0.0.0:(container B needed port)/route</code>.</p></li>
  <li><p>These fails.</p></li>
  </ul>
  
  <p>How could I call B inside A without getting and changing IP based on the network every time?</p>
  
Comments: CC BY-SA 4.0
Comments: 2018-12-20T16:03:49.347Z
Comments: by using the container name as the hostname
Comments: Sathyajith Bhat
Tags: <docker><networking>
Title: call container B inside container A using docker networks
UserDisplayName: lifeguru42
ThreadText: # call container B inside container A using docker networks
  
  (Asked by: username_0 on 2018-12-20)
  
  * I have two docker containers A and B that runs on the same user-defined network.
  * Container A has a port published, container B hasnt.
  * I do my requests on container's A published port, but container A needs to do requests on container B.
  * The requests to B inside A are mapped to `0.0.0.0:(container B needed port)/route`.
  * These fails.
  
  How could I call B inside A without getting and changing IP based on the network every time?
  
  **Tags:** docker, networking
  
  > **Comments:**
  > **username_1**: by using the container name as the hostname  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2018-12-28. Score: 2 | Accepted answer
  
  If you have a [user-defined network](https://docs.docker.com/v17.09/engine/userguide/networking/#user-defined-networks) set to bridge, you can access other containers by their container's name which is automatically as hostname for containers inside same network.
  
  So from `containerA` you could do `ping containerB` without problems. In your case it would be changing the setting to `containerB_name:(container B needed port)/route`
  
  
  ---
  
  