title: How can one deploy elasticsearch on docker swarm without declaring a service for each es node?
body: <p>My idea here was to specifically put set the endpoint_mode to dnsrr in hopes that each elasticsearch task in the service would pick up a random IP address when starting the discovery seeding process.  This did not work.  What happens it that it goes into a loop while seeding and never decides on a master.  <em>I specifically want to find some elegant configuration to deploy this on every node that doesn't include static configuration files or multiple service declarations in the compose-file</em>.</p>
  <pre><code>  elasticsearch:
      image: docker.elastic.co/elasticsearch/elasticsearch:7.9.3
      environment:
        - cluster.name=es-cluster
        - discovery.type=zen
        - discovery.seed_hosts=elasticsearch
        - cluster.initial_master_nodes=elasticsearch
        - bootstrap.memory_lock=false
        - &quot;ES_JAVA_OPTS=-Xms512m -Xmx512m&quot;
        - network.host=0.0.0.0
      volumes:
        - elasticsearch_data:/usr/share/elasticsearch/data
      networks:
        - elasticsearch
      deploy:
        mode: global
        endpoint_mode: dnsrr
  
  volumes:
    ...
    elasticsearch_data:
  
  networks:
    ...
    elasticsearch:
  </code></pre>
  <p>After deploying I just see this in the logs repeatedly (for each task):</p>
  <pre><code>web-services_elasticsearch.0.a6ilzu8ev6sp@dsnode3.&lt;redacted&gt;    | {&quot;type&quot;: &quot;server&quot;,
  &quot;timestamp&quot;: &quot;2020- 11-10T21:47:38,443Z&quot;, &quot;level&quot;: &quot;WARN&quot;, &quot;component&quot;: 
  &quot;o.e.c.c.ClusterFormationFailureHelper&quot;, &quot;cluster.name&quot;: &quot;es-cluster&quot;, &quot;node.name&quot;: 
  &quot;718a5740c014&quot;, &quot;message&quot;: &quot;master not discovered yet, this node has not previously 
  joined a bootstrapped (v7+) cluster, and this node must discover master-eligible 
  nodes [elasticsearch] to bootstrap a cluster: have discovered [{718a5740c014}
  {wMUW_UyQSzSxJDaz5jYVUw} {iBXmoZqHSp24fKSEUvuUpw}{10.0.46.129}{10.0.46.129:9300}
  {dilmrt} {ml.machine_memory=67428794368, xpack.installed=true, transform.node=true, 
  ml.max_open_jobs=20}, {99680d51349a}{BBqgO_1wRamiJZGibrhVTw}{WH6Oy5gOR1Cqs-2LUzu9Mw}
  {10.0.46.123} {10.0.46.123:9300}{dilmrt}{ml.machine_memory=67424575488, 
  ml.max_open_jobs=20,  xpack.installed=true, transform.node=true}, {27bf85fa9967}
  {Fm9r8aX4Rr-xa8AF_dUaLQ} {LsL5cXghTayDtXtLeWGV3Q}{10.0.46.126}{10.0.46.126:9300}
  {dilmrt} {ml.machine_memory=67424575488, ml.max_open_jobs=20, xpack.installed=true, 
  transform.node=true},  {fc2900a7227a}{FUztkTZQQuWqi3lyuOOfSQ}{JzACTEvzSnepc9RGXBXCzw}
  {10.0.46.131} {10.0.46.131:9300}{dilmrt}{ml.machine_memory=67428794368, 
  ml.max_open_jobs=20,  xpack.installed=true, transform.node=true}, {7b23784db269}
  {Dn472Qx5RyekUMY2jeLjIA}{w- m1g1BtS6SzZkttZEidnA}{10.0.46.122}{10.0.46.122:9300}
  {dilmrt}{ml.machine_memory=67424575488,  ml.max_open_jobs=20, xpack.installed=true, 
  transform.node=true}, {7d41b0583448} {1pj_6kJZQu6n39waIzcvQQ}{xwNHOG15Q_6jwY20BbBuyQ}
  {10.0.46.125}{10.0.46.125:9300}{dilmrt} {ml.machine_memory=67428794368, 
  ml.max_open_jobs=20, xpack.installed=true, transform.node=true}];  discovery will 
  continue using [10.0.46.123:9300, 10.0.46.126:9300, 10.0.46.131:9300, 
  10.0.46.122:9300,  10.0.46.125:9300] from hosts providers and [{718a5740c014}
  {wMUW_UyQSzSxJDaz5jYVUw} {iBXmoZqHSp24fKSEUvuUpw}{10.0.46.129}{10.0.46.129:9300}
  {dilmrt} {ml.machine_memory=67428794368, xpack.installed=true, transform.node=true,
  ml.max_open_jobs=20}]  from last-known cluster state; node term 0, last-accepted 
  version 0 in term 0&quot; }
  </code></pre>
  <p>I feel like it's just a matter of the node.name not matching the hostname or something BUT the hostnames are being set correctly.  Example:</p>
  <pre><code># docker exec -it web-services_elasticsearch.e3eaakkldj7pa3ygwkqwxts4i.7gjyxyjfjscve6rw41of7fyld hostname
  fc2900a7227a
  </code></pre>
  <p>Any ideas would be greatly appreciated.</p>