title: Trying to setup elasticsearch cluster with docker-compose
body: <p>My environment is two physical machine, both running in docker-compose.</p>
  
  <p>I want to create elasticsearch cluster cross two docker container.</p>
  
  <p><a href="https://i.stack.imgur.com/mw1so.png" rel="nofollow noreferrer">My architecture like this</a></p>
  
  <p>two container can't connected each other, any ideas?</p>
  
  <p>docker image is using elasticsearch:5.4.2</p>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '2'
  
  services:
    elasticsearch:
      image: es:542
      hostname: es2
      container_name: es2
      user: elasticsearch
      ports:
      - 9200:9200
      - 9300:9300
      environment:
      - ES_JAVA_OPTS=-Xms1g -Xmx1g
      command: /usr/share/elasticsearch/bin/elasticsearch
  </code></pre>
  
  <p>elasticsearch.yml</p>
  
  <pre><code>http.host: 0.0.0.0
  transport.host: 0.0.0.0
  discovery.zen.minimum_master_nodes: 2
  
  cluster.name: prod_es_cluster
  node.name: prod_es_node1
  node.master: true
  node.data: true
  discovery.zen.ping_timeout: 10s
  
  network.host: 0.0.0.0
  network.bind_host: 0.0.0.0
  network.publish_host: 0.0.0.0
  transport.tcp.port: 9300
  discovery.zen.ping.unicast.hosts: ["127.0.0.1", "[::1]"]
  </code></pre>
  
  <p>and logs</p>
  
  <pre><code>ES1
  </code></pre>
  
  <p>[2017-11-09T05:56:10,552][INFO ][o.e.t.TransportService ] [prod_es_node1] publish_address <code>{172.24.0.2:9300}, bound_addresses {[::]:9300}</code>
  [2017-11-09T05:56:10,558][INFO ][o.e.b.BootstrapChecks ] [prod_es_node1] bound or publishing to a non-loopback or non-link-local address,enforcing bootstrap checks
  [2017-11-09T05:56:40,576][WARN ][o.e.n.Node ][prod_es_node1]<code>timed out while waiting for initial discovery state - timeout: 30s</code>
  [2017-11-09T05:56:40,584][INFO ][o.e.h.n.Netty4HttpServerTransport] [prod_es_node1] publish_address <code>{172.24.0.2:9200}, bound_addresses {[::]:9200}</code>
  [2017-11-09T05:56:40,587][INFO ][o.e.n.Node ] [prod_es_node1] started</p>
  
  <pre><code>ES2
  </code></pre>
  
  <p>[2017-11-09T09:37:20,084][WARN ][o.e.d.z.ZenDiscovery ] [prod_es_node2]failed to connect to master [{prod_es_node1}{BxKzhOnJTUC50cYTz_Hm fA}{zqtU07jfQJOrmB9AYL01Ig}<code>{172.24.0.2}{172.24.0.2:9300}], retrying...</code>
  org.elasticsearch.transport.ConnectTransportException:[prod_es_node1]<code>[172.24.0.2:9300] connect_timeout[30s]</code>
  at org.elasticsearch.transport.netty4.Netty4Transport.connectToChannels(Netty4Transport.java:361) ~[?:?]
  at org.elasticsearch.transport.TcpTransport.openConnection(TcpTransport.java:549) ~[elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.transport.TcpTransport.connectToNode(TcpTransport.java:473) ~[elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:315) ~[elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.transport.TransportService.connectToNode(TransportService.java:302) ~[elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.discovery.zen.ZenDiscovery.joinElectedMaster(ZenDiscovery.java:468) [elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.discovery.zen.ZenDiscovery.innerJoinCluster(ZenDiscovery.java:420) [elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.discovery.zen.ZenDiscovery.access$4100(ZenDiscovery.java:83) [elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.discovery.zen.ZenDiscovery$JoinThreadControl$1.run(ZenDiscovery.java:1197) [elasticsearch-5.4.2.jar:5.4.2]
  at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:569) [elasticsearch-5.4.2.
  jar:5.4.2]
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0_131]
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0_131]
  at java.lang.Thread.run(Thread.java:748) [?:1.8.0_131]
  Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException:<code>Connection refused: 172.24.0.2/172.24.0.2:9300</code>
  at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[?:?]</p>