0

I'm using pymongo to handle my Mongo database, and I want to set it up, as a replica set, with Mongo 5.0 and minikube.

The relevant part of my minikube is:

mongo1:
  build:
      args:
        DOCKER_REGISTRY: ${DOCKER_REGISTRY}
      context: .
      dockerfile: build/mongo/Dockerfile
    image: <myfolder>/mongo:latest
    container_name: mongo1
    environment:
      MONGO_INITDB_DATABASE: <project>
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: <password>
      MONGO_USERNAME: <username>
      MONGO_PASSWORD: <password>
      MONGO_HOSTNAME: mongo

    restart: always
    networks:
      - mongo-network
    command: --auth --oplogSize 32 --quiet --bind_ip_all --keyFile /keys/replica.key --replSet ${PROJECT_NAME} --logpath /dev/stdout
    ports:
      - 27018:27017
    volumes:
      - mongodb:/data/db
      - ${MINIKUBE_REPO_PATH}/src/setup/mongo-initdb.d:/docker-entrypoint-initdb.d/
mongo2:
build:
      args:
        DOCKER_REGISTRY: ${DOCKER_REGISTRY}
      context: .
      dockerfile: build/mongo/Dockerfile
    image: <myfolder>/mongo:latest
    container_name: mongo2
    depends_on:
      - mongo1
    environment:
      MONGO_INITDB_DATABASE: <project>
      MONGO_INITDB_ROOT_USERNAME: admin
      MONGO_INITDB_ROOT_PASSWORD: <password>
      MONGO_USERNAME: <user>
      MONGO_PASSWORD: <password>
      MONGO_HOSTNAME: mongo

    restart: always
    networks:
      - mongo-network
    command: --auth --oplogSize 32 --quiet --bind_ip_all --keyFile /keys/replica.key --replSet ${PROJECT_NAME} --logpath /dev/stdout
    ports:
      - 27018:27017
    volumes:
      - mongodb:/data/db
      - ${MINIKUBE_REPO_PATH}/src/setup/mongo-initdb.d:/docker-entrypoint-initdb.d/

networks:
  mongo-network:
    driver: bridge

My Dockerfile:

FROM mongo:5.0
RUN mkdir /keys
RUN echo <replica.key> > /keys/replica.key
RUN chmod 400 /keys/replica.key
RUN chown 999:999 /keys/replica.key
RUN chmod 400 /keys/replica.key

Then I start this using the following configuration for my rs.initiate():

{
        "_id": "dbrs",
        "version": 1,
        "members": [
            {
                "_id": 1,
                "host": "mongo1:27017",
                "priority": 1
            },
            {
                "_id": 2,
                "host": "mongo2:27018",
                "priority": 2
            },
       ]
}

The containers are created, but I'm having the following errors:

  • In mongo1 : This node is not a member of the config and Failed to refresh key cache

  • In mongo2: Another mongod instance is already running on the /data/db directory . I can confirm that no second mongo is running in that container. Unless it's considering that another Mongo to be the one on the first container Am I missing something here?

Carabes
  • 532
  • 2
  • 4
  • 16

0 Answers0