Let's try to define a better and easier way to set up a MongoDB replica set.
We'll start by creating three mongo services. Later on, each will become a member of a Mongo replica set:
for i in 1 2 3; do
docker service create --name go-demo-db-rs$i \
--reserve-memory 100m \
--network go-demo \
mongo:3.2.10 mongod --replSet "rs0"
MEMBERS="$MEMBERS go-demo-db-rs$i"
done
The only difference, when compared with the previous command we used to create mongo services, is the addition of the environment variable MEMBERS. It holds service names of all MongoDBs. We'll use that as the argument for the next service.
Since the official mongo image does not have a mechanism to configure Mongo replica sets, we'll use a custom one. Its purpose will be only to configure Mongo replica sets.
The definition of the...