Connect to docker containers with just service name and task slot?

Viewed 714

I’m attempting to use docker swarm to manage a cluster of CouchDB 2 nodes where each node is a service. It is great that I can use the container name, which is comprised of {{.Service.Name}}.{{.Task.Slot}}.{{.Node.ID}} to connect the nodes, e.g. couchdb.1.52286blz1o0c7ym508sne6jyg. The issue is that the Node ID is a dynamic value and therefore my node names are constantly changing. This dynamic Node ID doesn’t play well with CouchDB’s node configuration, i.e. you really need static names for your nodes like couchdb.1, couchdb.2, etc…

Is there a way to configure the containers so that they can connect to each other with just {{.Service.Name}}.{{.Task.Slot}}? This way, if a node dies and is restarted, the restarted node will retake the dead node’s place automatically.

Docker run appears to have a --network-alias command that can be used to achieve this configuration, but nothing like --network-alias appears to be available for docker swarm.

0 Answers
Related