# Run a Elasticsearch Cluster with Docker

**URL:** https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455
**Category:** Elasticsearch
**Created:** [July 17, 2017, 9:08pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455 "2017-07-17T21:08:26Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![byjg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byjg/32/16517_2.png) [@byjg](https://discuss.elastic.co/u/byjg)
#### Post date: [July 17, 2017, 9:08pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455/1 "2017-07-17T21:08:26Z")

</div>

I am having problems to create a cluster with Elasticsearch docker image .

I am deploying two different servers in my local network. There is no firewalls and the servers can communicate each others.

The command I am using is:

```
docker run --name elasticsearch-container \
    -e cluster.name=docker-cluster \
    -e network.publish_host=192.168.1.161 \
    -e bootstrap.memory_lock=true \
    -e node.name=main01 --publish-all \
    -p 9200:9200 \
    -d docker.elastic.co/elasticsearch/elasticsearch:5.5.0

```

And on another server

```
docker run --name elasticsearch-container \
    -e cluster.name=docker-cluster \
    -e network.publish_host=192.168.1.162 \
    -e bootstrap.memory_lock=true \
    -e discovery.zen.ping.unicast.hosts=192.168.1.161 \
    -e node.name=main02 --publish-all \
    -p 9200:9200 \
    -d docker.elastic.co/elasticsearch/elasticsearch:5.5.0

```

But the cluster does not work.

The message I am receiving is:

[o.e.c.s.ClusterService] [main02] new\_master {main02}{Pq1uX-fAS2mPnw5IQ5fSyQ}{GIBd58CBSlaAMIkHaNrKtQ}{192.168.1.181}{192.168.1.181:9300}{ml.enabled=true}, reason: zen-disco-elected-as-master ([0] nodes joined)

I mapped a local config to the docker image and the config is :

```
xpack.security.enabled: false
cluster.name: "docker-cluster"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
bootstrap.memory_lock: true

```

What I am doing wrong?

---

<div class="post-metadata">

### Author: ![dliappis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dliappis/32/56174_2.png) [@dliappis](https://discuss.elastic.co/u/dliappis)
#### Post date: [July 21, 2017, 3:35pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455/2 "2017-07-21T15:35:42Z")

</div>

Hello! Thanks for your interest in the Elasticsearch Docker images.

I think the main issue you are having here is the use of `--publish-all`. You should replace it with `-p 9300:9300` for the transport port as `--publish-all` will randomly allocate an external port for your containers.

You can inspect the container ports with `docker port elasticsearch-container`.

I have prepared a [Vagrantfile](https://gist.github.com/dliappis/49c435e7bca8413654c5856e72a3f7f6) (uses VirtualBox) to use for replicating your scenario. This creates an `elasticsearch.yml` with your custom config params under `/home/vagrant`.

Following `vagrant up && vagrant ssh m01`, if I `docker run` using `--publish-all`:

```auto
vagrant@m01:~$ docker run --ulimit memlock=-1:-1 --name elasticsearch-container -v $PWD/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -e cluster.name=docker-cluster -e bootstrap.memory_lock=true -e node.name=main01 -e network.publish_host=192.168.124.101 --publish-all -p 9200:9200 -d docker.elastic.co/elasticsearch/elasticsearch:5.5.0
1051cc374b32f14d977c7eb8757b666f857b91b7ab68c37736a7b2f93e66aa7e

vagrant@m01:~$ docker port elasticsearch-container 
9200/tcp -> 0.0.0.0:9200
9300/tcp -> 0.0.0.0:32768

vagrant@m01:~$ nc -v localhost 9200
Connection to localhost 9200 port [tcp/*] succeeded!
^C
vagrant@m01:~$ nc -v localhost 9300
nc: connect to localhost port 9300 (tcp) failed: Connection refused
nc: connect to localhost port 9300 (tcp) failed: Connection refused

```

Whereas, I can successfully do the following:

```auto
vagrant destroy -f

vagrant up

vagrant ssh m01 -c 'docker run --ulimit memlock=-1:-1 --name elasticsearch-container -v $PWD/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -e cluster.name=docker-cluster -e bootstrap.memory_lock=true -e node.name=main01 -e network.publish_host=192.168.124.101 -p 9300:9300 -p 9200:9200 -d docker.elastic.co/elasticsearch/elasticsearch:5.5.0'

vagrant ssh m02 -c 'docker run --ulimit memlock=-1:-1 --name elasticsearch-container -v $PWD/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml -e network.publish_host=192.168.124.102 -e cluster.name=docker-cluster -e bootstrap.memory_lock=true -e node.name=main02 -e discovery.zen.ping.unicast.hosts=192.168.124.101 -p 9200:9200 -p 9300:9300 -d docker.elastic.co/elasticsearch/elasticsearch:5.5.0'

$ vagrant ssh m02 -c 'curl -s localhost:9200/_cluster/health | jq .'
{
  "cluster_name": "docker-cluster",
  "status": "green",
  "timed_out": false,
  "number_of_nodes": 2,
  "number_of_data_nodes": 2,
  "active_primary_shards": 2,
  "active_shards": 4,
  "relocating_shards": 0,
  "initializing_shards": 0,
  "unassigned_shards": 0,
  "delayed_unassigned_shards": 0,
  "number_of_pending_tasks": 0,
  "number_of_in_flight_fetch": 0,
  "task_max_waiting_in_queue_millis": 0,
  "active_shards_percent_as_number": 100
}
Connection to 127.0.0.1 closed.

```

---

<div class="post-metadata">

### Author: ![byjg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/byjg/32/16517_2.png) [@byjg](https://discuss.elastic.co/u/byjg)
#### Post date: [July 21, 2017, 6:42pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455/3 "2017-07-21T18:42:37Z")

</div>

Hey Dimitrios,

You saved my life 🙂

It worked!!!!! I just tested right now and it is OK.

Thank you!

---

<div class="post-metadata">

### Author: ![dliappis](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dliappis/32/56174_2.png) [@dliappis](https://discuss.elastic.co/u/dliappis)
#### Post date: [July 21, 2017, 6:48pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455/4 "2017-07-21T18:48:48Z")

</div>

Totally my pleasure Joao!

---

<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: [August 18, 2017, 6:48pm UTC](https://discuss.elastic.co/t/run-a-elasticsearch-cluster-with-docker/93455/5 "2017-08-18T18:48:49Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
