title: Bitnami MongoDB Replica Set on Google Compute Engine
body: <p>I have three <a href="https://cloud.google.com/container-optimized-os/docs?hl=de" rel="nofollow noreferrer">container optimised VMs</a> running on Google Compute Engine (GCE) with each a <a href="https://github.com/bitnami/bitnami-docker-mongodb" rel="nofollow noreferrer">Bitnami MongoDB Docker Container</a>, one should be the primary Mongo DB Instance and two should be secondary.</p>
  <p>When creating the VMs, I specified the Container Image as <em>&quot;bitnami/mongodb:latest&quot;</em> and set the environment variables according to the bitnami <a href="https://github.com/bitnami/bitnami-docker-mongodb#setting-up-replication" rel="nofollow noreferrer">documentation</a> using <code>gce-container-declaration</code> (also possible via the UI under &quot;Advanced Container Options&quot;)</p>
  <p>I can connect to the primary mongodb with the via <code>MONGODB_ROOT_PASSWORD</code> defined password and also the other VMs are up and are listening on their 27017 ports. The VMs can also reach each other, so the VPC and Firewall Rules are ok with <code>Port 27017, 22 and 80 INGRESS / EGRESS</code>.</p>
  <p>But, when I want to get the replica set status <code>rs.status()</code> on the primary, I always get an <code>&quot;errmsg&quot; : &quot;no replset config has been received&quot;</code> error. So the nodes don't create a Replica Set...
  With Docker-Compose this works out of the box and the Bitnami Image also should init the Replica Set automatically, shouldn't it?</p>
  <p>I tried a lot of things including using <code>MONGODB_ADVERTISED_HOSTNAME</code> with custome GCE VM Hostnames, but nothing works and I don't have any Idea how to find the issue.</p>
  <p><a href="https://i.stack.imgur.com/XUtZf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XUtZf.png" alt="enter image description here" /></a></p>
  <p>Primary Node - Container Env. Vars:</p>
  <pre><code>MONGODB_ROOT_PASSWORD = 'password123'
  MONGODB_REPLICA_SET_NAME = 'rep'
  MONGODB_REPLICA_SET_MODE = 'primary'
  MONGODB_REPLICA_SET_KEY = '321abc123'
  </code></pre>
  <p>Secondary1 Node - Container Env. Vars:</p>
  <pre><code>MONGODB_PRIMARY_ROOT_PASSWORD = 'password123'
  MONGODB_REPLICA_SET_NAME = 'rep'
  MONGODB_PRIMARY_HOST = '${VPC_LOCAL_IP_PRIMARY_NODE}'
  MONGODB_PRIMARY_PORT_NUMBER = '27017'
  MONGODB_REPLICA_SET_MODE = 'secondary'
  MONGODB_REPLICA_SET_KEY = '321abc123'
  </code></pre>
  <p>Secondary2 Node - Container Env. Vars:</p>
  <pre><code>MONGODB_PRIMARY_ROOT_PASSWORD = 'password123'
  MONGODB_REPLICA_SET_NAME = 'rep'
  MONGODB_PRIMARY_HOST = '${VPC_LOCAL_IP_PRIMARY_NODE}'
  MONGODB_PRIMARY_PORT_NUMBER = '27017'
  MONGODB_REPLICA_SET_MODE = 'secondary'
  MONGODB_REPLICA_SET_KEY = '321abc123'
  </code></pre>