horiyomi
horiyomi

Reputation: 25

Mongo db replicaset locally with docker-compose.yml

Here is a sample of my docker-compose.yml file

Below the docker-compose.yml file is my is also the log response, any help will be very much appreciated. Also, the other replica don't come up when i run docker-compose up.

    image: 'bitnami/mongodb:latest'
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongo
      - MONGODB_REPLICA_SET_MODE=primary
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGODB_ROOT_PASSWORD=P@ssword1
      - MONGODB_REPLICA_SET_KEY=replicasetkey123
    ports:
      - "27017:27017"

    volumes:
      - '~/docker/volumes/mongodb_master_data:/bitnami'

  mongodb-secondary:
    image: 'bitnami/mongodb:latest'
    depends_on:
      - mongo
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-secondary
      - MONGODB_REPLICA_SET_MODE=secondary
      - MONGODB_INITIAL_PRIMARY_HOST=mongo
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=P@ssword1
      - MONGODB_REPLICA_SET_KEY=replicasetkey123

  mongodb-arbiter:
    image: 'bitnami/mongodb:latest'
    depends_on:
      - mongo
    environment:
      - MONGODB_ADVERTISED_HOSTNAME=mongodb-arbiter
      - MONGODB_REPLICA_SET_MODE=arbiter
      - MONGO_INITDB_ROOT_USERNAME=admin
      - MONGODB_INITIAL_PRIMARY_HOST=mongo
      - MONGODB_INITIAL_PRIMARY_PORT_NUMBER=27017
      - MONGODB_INITIAL_PRIMARY_ROOT_PASSWORD=P@ssword1
      - MONGODB_REPLICA_SET_KEY=replicasetkey123

mongo_1              | {"t":{"$date":"2022-03-22T13:11:13.109+00:00"},"s":"I",  "c":"CONTROL",  "id":20714,   "ctx":"LogicalSessionCacheRefresh","msg":"Failed to refresh session cache, will try again at the next refresh interval","attr":{"error":"NotYetInitialized: Replication has not yet been configured"}}
mongo_1              | {"t":{"$date":"2022-03-22T13:11:13.124+00:00"},"s":"I",  "c":"CONTROL",  "id":20711,   "ctx":"LogicalSessionCacheReap","msg":"Failed to reap transaction table","attr":{"error":"NotYetInitialized: Replication has not yet been configured"}}
mongo_1              | {"t":{"$date":"2022-03-22T13:11:14.313+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"Checkpointer","msg":"WiredTiger message","attr":{"message":"[1647954674:313273][1:0x7f1a828b6700], WT_SESSION.checkpoint: [WT_VERB_CHECKPOINT_PROGRESS] saving checkpoint snapshot min: 92, snapshot max: 92 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 548"}}
mongo_1              | {"t":{"$date":"2022-03-22T13:11:19.887+00:00"},"s":"I",  "c":"-",        "id":4939300, "ctx":"monitoring-keys-for-HMAC","msg":"Failed to refresh key cache","attr":{"error":"NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.","nextWakeupMillis":33000}}
mongo_1              | {"t":{"$date":"2022-03-22T13:11:52.890+00:00"},"s":"I",  "c":"-",        "id":4939300, "ctx":"monitoring-keys-for-HMAC","msg":"Failed to refresh key cache","attr":{"error":"NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.","nextWakeupMillis":33200}}
mongo_1              | {"t":{"$date":"2022-03-22T13:12:14.342+00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"Checkpointer","msg":"WiredTiger message","attr":{"message":"[1647954734:342425][1:0x7f1a828b6700], WT_SESSION.checkpoint: [WT_VERB_CHECKPOINT_PROGRESS] saving checkpoint snapshot min: 94, snapshot max: 94 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 548"}}
mongo_1              | {"t":{"$date":"2022-03-22T13:12:26.093+00:00"},"s":"I",  "c":"-",        "id":4939300, "ctx":"monitoring-keys-for-HMAC","msg":"Failed to refresh key cache","attr":{"error":"NotYetInitialized: Cannot use non-local read concern until replica set is finished initializing.","nextWakeupMillis":33400}}

Upvotes: 0

Views: 6282

Answers (1)

Mark S.
Mark S.

Reputation: 4017

You need to setup the configuration of the replicaset. Otherwise Mongo doesn't know how to set it up.. Here's an article which I followed to get the replicaset working locally through a docker-compose file.

Upvotes: 1

Related Questions