<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>

CC BY-SA 4.0
2018-12-28T19:10:19.120Z
2018-12-28T19:10:19.120Z
Alberto Castillo G
<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>

CC BY-SA 4.0
2018-12-20T16:03:49.347Z
by using the container name as the hostname
Sathyajith Bhat
<docker><networking>
call container B inside container A using docker networks
lifeguru42
# 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`


---

