Automatic self-configuration of an etcd cluster as a Docker swarm service : <p>I want to find a way to deploy an etcd cluster as a Docker Swarm service that would automatically configure itself without any interaction. Basically, I think of something in spirit of this command: </p>

<pre><code>docker service create --name etcd --replicas 3 my-custom-image/etcd
</code></pre>

<p>I'm assuming that overlay network is configured to be secure and provide both encryption and authentication, so I believe I don't need TLS, not even <code>--auto-tls</code>. Don't want an extra headache finding a way to provision the certificates, when this can be solved on the another layer.</p>

<p>I need an unique <code>--name</code> for each instance, but I can get that from an entrypoint script that would use <code>export ETCD_NAME=$(hostname --short)</code>.</p>

<p>The problem is, I'm stuck on initial configuration. Based on the <a href="https://coreos.com/etcd/docs/latest/op-guide/clustering.html" rel="noreferrer">clustering guide</a> there are three options, but none seems to fit:</p>

<ul>
<li>The DNS discovery scenario is closest to what I'm looking for, but Docker <a href="https://github.com/moby/moby/issues/24605" rel="noreferrer">doesn't support DNS SRV records</a> discovery at the moment. I can lookup <code>etcd</code> and I will get all the IPs of my nodes' containers, but there are no <code>_etcd-server._tcp</code> records.</li>
<li>I cannot automatically build <code>ETCD_INITIAL_CLUSTER</code> because while I know the IPs, I don't know the names of the other nodes and I'm not aware about any way to figure those out. (I'm not going to expose Docker API socket to etcd container for this.)</li>
<li>There is no preexisting etcd cluster, and while supplying the initial configuration URI from discovery.etcd.io is a possible workaround I'm interested in not doing this. I'm aiming for "just deploy a stack from this <code>docker-compose.yml</code> and it'll automatically do the right thing, no questions asked" no-brainer scenario.</li>
</ul>

<p>Is there any trick I can pull?</p>
