title: MongoDB single node replicaset never finishing instanciating Error: "Cannot use non-local read concern until replica set is finished initializing"
body: <p>I'm trying to setup a mongodb replicaset as a single node in a docker container because I need to use the transactions to watch over changes in collections.</p>
  <p>The issue I'm having is that the replicaset seems to never finish to instanciate and the loog display the following line every seconds:</p>
  <pre><code>{&quot;t&quot;:{&quot;$date&quot;:&quot;2022-05-19T21:31:57.421+00:00&quot;},&quot;s&quot;:&quot;I&quot;,  &quot;c&quot;:&quot;-&quot;,        &quot;id&quot;:4939300, &quot;ctx&quot;:&quot;monitoring-keys-for-HMAC&quot;,&quot;msg&quot;:&quot;Failed to refresh key cache&quot;,&quot;attr&quot;:{&quot;error&quot;:&quot;NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.&quot;,&quot;nextWakeupMillis&quot;:9200}}
  </code></pre>
  <p>I've tried every tutorials I've found, every stackoverflow issue, they all say the same thing, the configuration should be fairly simple and work with what I have now.</p>
  <p>Here's my configurations:</p>
  <p><strong>mongo-init.js</strong> (I removed the db and collection creation in hope to make it work)</p>
  <pre class="lang-js prettyprint-override"><code>const rsconf = {
      _id: &quot;rs0&quot;,
      members: [
          {
              _id: 0,
              host: '127.0.0.1:27017',
          },
      ]
  };
  
  rs.initiate(rsconf);
  </code></pre>
  <p><strong>Dockerfile</strong> (I use a custom image because I'm on docker windows and I can't set proper file permission on a file if I mount it in the container from the host. It's a POC security is not a concern anyway)</p>
  <pre><code>FROM mongo:latest
  COPY mongo/mongo-conf/mongodb.key /mongodb.key
  RUN chmod 600 /mongodb.key
  RUN chown 999:999 /mongodb.key
  
  # To solve &quot;Unable to open() file /home/mongodb/.dbshell - source: https://github.com/docker-library/mongo/issues/323#issuecomment-494648458
  RUN mkdir &quot;/home/mongodb&quot;
  RUN touch &quot;/home/mongodb/.dbshell&quot;
  RUN chown -R 999:999 /home/mongodb
  
  ENTRYPOINT [&quot;docker-entrypoint.sh&quot;]
  </code></pre>
  <p><strong>docker-compose.yml</strong></p>
  <pre class="lang-yaml prettyprint-override"><code>version: '3.8'
  services:
    # Mongodb database
    mongo:
      image: mongo-custom
      container_name: mongo
      command: --bind_ip_all --replSet rs0 --keyFile /mongodb.key
      #    restart: unless-stopped
      environment:
        MONGO_INITDB_ROOT_USERNAME: mogoadm
        MONGO_INITDB_ROOT_PASSWORD: mogopwd
      ports:
        - &quot;27017:27017&quot;
      volumes:
        - ./mongo/database/mongodb/db:/data/db
        - ./mongo/mongo-init:/docker-entrypoint-initdb.d:ro
  </code></pre>
  <p>I did read the <a href="https://www.mongodb.com/docs/manual/tutorial/deploy-replica-set/" rel="nofollow noreferrer">official documentation</a> and I see no functionnal difference, I'm really banging my head against a wall here trying to figure out what I did wrong?</p>