# Cannot cluster Elasticsearch when using Docker bridge network

**URL:** <https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416>\
**Category:** Elasticsearch\
**Created:** [May 6, 2016, 3:28pm UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416 "2016-05-06T15:28:53Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![DK\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dk_3/32/48003_2.png) [@DK\_3](https://discuss.elastic.co/u/DK_3)\
**Post date:** [May 6, 2016, 3:28pm UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/1 "2016-05-06T15:28:53Z")

</div>

I have elasticserach master running on 2 hosts (10.123.4.10 & 10.123.4.11).  
But they cannot see each other when using the Docker `bridge` network.

My `docker-compose.yml`:

```auto
version: '2'
services:

  elasticsearch:
    image: elasticsearch:2.3.0
    ports:
        - "9200:9200"
    environment:
        - HOST_HOSTNAME=${HOST_HOSTNAME}
    volumes:
      - ${PWD}/config/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml
    restart: always
    networks:
      - es

networks:
   es:
     driver: bridge

```

networks:  
es:  
driver: bridge`

My `elasticsearch.yml` files:

node1

```auto
cluster.name: "es-cluster"
node.name: ${HOST_HOSTNAME}
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping.multicast.enabled: false
network.bind_host: 0.0.0.0
network.publish_host: 10.123.4.10
discovery.zen.ping.unicast.hosts: 10.123.4.10, 10.123.4.11

```

node2

```auto
cluster.name: "es-cluster"
node.name: ${HOST_HOSTNAME}
discovery.zen.minimum_master_nodes: 2
discovery.zen.ping.multicast.enabled: false
network.bind_host: 0.0.0.0
network.publish_host: 10.123.4.11
discovery.zen.ping.unicast.hosts: 10.123.4.10, 10.123.4.11

```

When I switch from bridge to `network_mode: "host"` the nodes can see each other

* * *

Elasticsearch Docker image version `2.3.0`  
Docker version `1.11.1, build 5604cbe`  
docker-compose version `1.7.0, build 0d7bf73`  
Docker hosts running Ubuntu `14.04.4 LTS`

---

<div class="post-metadata">

**Author:** ![twnone](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@twnone](https://discuss.elastic.co/u/twnone)\
**Post date:** [May 9, 2016, 10:50am UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/2 "2016-05-09T10:50:13Z")

</div>

Hi,

When you put these containers on your **es** network, what is the ouput of following command ?

> docker network inspect es

---

<div class="post-metadata">

**Author:** ![DK\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dk_3/32/48003_2.png) [@DK\_3](https://discuss.elastic.co/u/DK_3)\
**Post date:** [May 9, 2016, 11:24am UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/3 "2016-05-09T11:24:51Z")

</div>

> [@twnone](#):
>
> docker network inspect

```auto
[
    {
        "Name": "es",
        "Id": "6e692ea87a53ead3b8651b9661bc1812125c6b0572351a5657b4dedda02feb2e",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.21.0.0/16",
                    "Gateway": "172.21.0.1/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {
            "eb37d9b2b1a58f51dbe298d288822f7c8ceb30b69636956d4aa01ddfb64aa776": {
                "Name": "elasticsearch",
                "EndpointID": "27567d038c484f58e040be10c60b6cace60740189f76cc10486e292f7c817716",
                "MacAddress": "02:42:ac:15:00:02",
                "IPv4Address": "172.21.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

```

---

<div class="post-metadata">

**Author:** ![twnone](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@twnone](https://discuss.elastic.co/u/twnone)\
**Post date:** [May 9, 2016, 11:47am UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/4 "2016-05-09T11:47:38Z")

</div>

OK, I misread your 1st post, I thought the two containers were running on the same host.

Anyway, as mentioned on the Docker documentation, host networking consists in running the container in the same network configuration as the host. ES nodes can recognize each other because they have the same IP as your host and as your ES configuration files.

However, with a bridge network, it is kind of NATted. So when you specify for each ES node (in elasticsearch.yml) its IP as [10.123.4.xxx](http://10.123.4.xxx), it won't recognize itself, because its real IP address is [172.21.0.xxx](http://172.21.0.xxx)

I don't know if my explanations are good and understandable, but I my guess is that you should either keep on using host network, [either use overlay network with docker swarm](https://docs.docker.com/engine/userguide/networking/get-started-overlay/).

---

<div class="post-metadata">

**Author:** ![DK\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dk_3/32/48003_2.png) [@DK\_3](https://discuss.elastic.co/u/DK_3)\
**Post date:** [May 9, 2016, 11:54am UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/5 "2016-05-09T11:54:12Z")

</div>

> [@twnone](#):
>
> NATted

Ya I figured it would still work. Since I'm using `network.bind_host` and `network.publish_host`

I should of added that I've followed this wiki:

> **[Docker Networking](https://www.elastic.co/blog/docker-networking)**

---

<div class="post-metadata">

**Author:** ![twnone](https://avatars.discourse-cdn.com/v4/letter/t/a87d85/32.png) [@twnone](https://discuss.elastic.co/u/twnone)\
**Post date:** [May 9, 2016, 12:08pm UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/6 "2016-05-09T12:08:03Z")

</div>

Did you also try with the default bridge network provided by Docker ?  
Because maybe this option would help NATting communications between the two containers :

> "com.docker.network.bridge.enable\_ip\_masquerade": "true",

If this work, maybe you could try creating your custom bridge network with this option enabled too ?

---

<div class="post-metadata">

**Author:** ![DK\_3](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dk_3/32/48003_2.png) [@DK\_3](https://discuss.elastic.co/u/DK_3)\
**Post date:** [May 9, 2016, 1:18pm UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/7 "2016-05-09T13:18:45Z")

</div>

> [@twnone](#):
>
> enable\_ip\_masquerade

Ya still same issue. I'll stick with `network_mode: "host"` for now

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:53pm UTC](https://discuss.elastic.co/t/cannot-cluster-elasticsearch-when-using-docker-bridge-network/49416/8 "2017-07-05T22:53:00Z")

</div>


