<p>When you <code>ping nginx</code> the docker swarm returns Virual IP of swarm service named "nginx" not the container ip. </p>

<p>This is is how internal load balancer works - you can have multiple replicas of "nginx" containers behind the "nginx" <a href="https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/" rel="nofollow noreferrer">service</a>. 
<a href="https://i.sstatic.net/CDR4P.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CDR4P.png" alt="enter image description here"></a></p>

CC BY-SA 4.0
2019-10-02T12:20:11.647Z
I see. That makes sense. I figured "I only have one instance, so why would there be something in front of it?". But it makes sense that there is always a load balancer in front as you might scale in the future and then it's already there. Thanks for the insight!
Worp
CC BY-SA 4.0
2019-10-02T06:30:02.673Z
2019-10-02T06:30:02.673Z
Vasiliy  Shakhunov
<p>I have a Docker overlay network which includes 2 containers and the loadbalancer for this network:</p>

<pre><code>    "Containers": {
        "0ece6b958aa6b451478b5004ba1b1681ec91b718b99a0c2c88b79d5e8e135a66": {
            "Name": "flvw_nginx.1.v9ycohipbvizlagm840o7jd0d",
            "EndpointID": "0fba09c56d5098efb3a89645a5dce575a12b5f3496d3839ce4e34bb29bc60091",
            "MacAddress": "02:42:0a:00:16:06",
            "IPv4Address": "10.0.22.6/24",
            "IPv6Address": ""
        },
        "25b2988afe5d0cf02f718831bf12858b3dccb875a3609804273da02bd4b422ac": {
            "Name": "flvw_pimcore.1.j3m0i52sksg0fmhdawzhwwhei",
            "EndpointID": "a2ea9ddcfba20b05017dda7a79af542ab09b0172a74f61be9fbb861fad39d008",
            "MacAddress": "02:42:0a:00:16:03",
            "IPv4Address": "10.0.22.3/24",
            "IPv6Address": ""
        },
        "lb-flvw_app": {
            "Name": "flvw_app-endpoint",
            "EndpointID": "c4cf9798cd3d2d8ee11057176c9f7395fd81546860f97c2623cd7f5043104294",
            "MacAddress": "02:42:0a:00:16:04",
            "IPv4Address": "10.0.22.4/24",
            "IPv6Address": ""
        }
    },
</code></pre>

<p>This states:</p>

<pre><code>pimcore = 10.0.22.3
nginx = 10.0.22.6
</code></pre>

<p>So I exec into the containers and the following commands.</p>

<p>On the pimcore container:</p>

<pre><code>[root@25b2988afe5d pimcore]# ip a | grep -i "10.0.22"
    inet 10.0.22.3/24 brd 10.0.22.255 scope global eth0

[root@25b2988afe5d pimcore]# ping nginx
PING nginx (10.0.22.5) 56(84) bytes of data.
64 bytes from 10.0.22.5 (10.0.22.5): icmp_seq=1 ttl=64 time=0.062 ms
64 bytes from 10.0.22.5 (10.0.22.5): icmp_seq=2 ttl=64 time=0.052 ms
^C
</code></pre>

<p>On the nginx container:</p>

<pre><code>[root@0ece6b958aa6 /]# ip a | grep -i "10.0.22"
    inet 10.0.22.6/24 brd 10.0.22.255 scope global eth0
[root@0ece6b958aa6 /]# ping pimcore
PING pimcore (10.0.22.2) 56(84) bytes of data.
64 bytes from 10.0.22.2 (10.0.22.2): icmp_seq=1 ttl=64 time=0.036 ms
64 bytes from 10.0.22.2 (10.0.22.2): icmp_seq=2 ttl=64 time=0.065 ms
</code></pre>

<p>Result:</p>

<p>Pimcore says its own IP is 10.0.22.3 (which corresponds to the network inspect output) and that nginx' IP is 10.0.22.5 (which does not correspond).</p>

<p>Nginx says its own IP is 10.0.22.6 (which corresponds to network inspect) and that pimcore's IP is 10.0.22.2 (which does not correspond).</p>

<p>Containers seem to see other containers "1 number off", in a way of speaking. Why?</p>

<p>My TCP/IP knowledge is definitely not high level, but this feels weird. Maybe someone can englighten me!</p>

<docker><networking>
Docker container and their IPs on overlay (swarm) networks
Worp
# Docker container and their IPs on overlay (swarm) networks

(Asked by: username_0 on 2019-10-01)

I have a Docker overlay network which includes 2 containers and the loadbalancer for this network:
    "Containers": {
        "0ece6b958aa6b451478b5004ba1b1681ec91b718b99a0c2c88b79d5e8e135a66": {
            "Name": "flvw_nginx.1.v9ycohipbvizlagm840o7jd0d",
            "EndpointID": "0fba09c56d5098efb3a89645a5dce575a12b5f3496d3839ce4e34bb29bc60091",
            "MacAddress": "02:42:0a:00:16:06",
            "IPv4Address": "10.0.22.6/24",
            "IPv6Address": ""
        },
        "25b2988afe5d0cf02f718831bf12858b3dccb875a3609804273da02bd4b422ac": {
            "Name": "flvw_pimcore.1.j3m0i52sksg0fmhdawzhwwhei",
            "EndpointID": "a2ea9ddcfba20b05017dda7a79af542ab09b0172a74f61be9fbb861fad39d008",
            "MacAddress": "02:42:0a:00:16:03",
            "IPv4Address": "10.0.22.3/24",
            "IPv6Address": ""
        },
        "lb-flvw_app": {
            "Name": "flvw_app-endpoint",
            "EndpointID": "c4cf9798cd3d2d8ee11057176c9f7395fd81546860f97c2623cd7f5043104294",
            "MacAddress": "02:42:0a:00:16:04",
            "IPv4Address": "10.0.22.4/24",
            "IPv6Address": ""
        }
    },

This states:
pimcore = 10.0.22.3
nginx = 10.0.22.6

So I exec into the containers and the following commands.
On the pimcore container:
[root@25b2988afe5d pimcore]# ip a | grep -i "10.0.22"
    inet 10.0.22.3/24 brd 10.0.22.255 scope global eth0

[root@25b2988afe5d pimcore]# ping nginx
PING nginx (10.0.22.5) 56(84) bytes of data.
64 bytes from 10.0.22.5 (10.0.22.5): icmp_seq=1 ttl=64 time=0.062 ms
64 bytes from 10.0.22.5 (10.0.22.5): icmp_seq=2 ttl=64 time=0.052 ms
^C

On the nginx container:
[root@0ece6b958aa6 /]# ip a | grep -i "10.0.22"
    inet 10.0.22.6/24 brd 10.0.22.255 scope global eth0
[root@0ece6b958aa6 /]# ping pimcore
PING pimcore (10.0.22.2) 56(84) bytes of data.
64 bytes from 10.0.22.2 (10.0.22.2): icmp_seq=1 ttl=64 time=0.036 ms
64 bytes from 10.0.22.2 (10.0.22.2): icmp_seq=2 ttl=64 time=0.065 ms

Result:
Pimcore says its own IP is 10.0.22.3 (which corresponds to the network inspect output) and that nginx' IP is 10.0.22.5 (which does not correspond).
Nginx says its own IP is 10.0.22.6 (which corresponds to network inspect) and that pimcore's IP is 10.0.22.2 (which does not correspond).
Containers seem to see other containers "1 number off", in a way of speaking. Why?
My TCP/IP knowledge is definitely not high level, but this feels weird. Maybe someone can englighten me!

**Tags:** docker, networking


---

## 1 answers

### Answer by username_1 on 2019-10-02. Score: 3 | Accepted answer

When you `ping nginx` the docker swarm returns Virual IP of swarm service named "nginx" not the container ip.

This is is how internal load balancer works - you can have multiple replicas of "nginx" containers behind the "nginx" [service](https://docs.docker.com/engine/swarm/how-swarm-mode-works/services/).
[![enter image description here](https://i.sstatic.net/CDR4P.png)](https://i.sstatic.net/CDR4P.png)

> **Comments:**
> **username_0**: I see. That makes sense. I figured "I only have one instance, so why would there be something in front of it?". But it makes sense that there is always a load balancer in front as you might scale in the future and then it's already there. Thanks for the insight!  

---

