Hello,
I am currently trying to install a mongo cluster on docker.
We already have such cluster with mongo 4.2 but for the new installation we wanted to use latest version of docker image.
I used the same docker-compose file but the data and config servers don’t want to start.
When looking at the docker logs, the error is:
BadValue: Cannot start a shardsvr as a standalone server. Please use the option --replSet to start the node as a replica set.
BadValue: Cannot start a configsvr as a standalone server. Please use the option --replSet to start the node as a replica set.
But I have the replSet in my commands.
After some try and errors, the error occurs when I add the init db environment variables to initialize the admin user.
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
I did the test also with mongo image version 5 and I have same behavior.
I works fine with mongo image 4.4.18
Here is my docker compose file
version: '3.5'
services:
# Router
mongo-router-01:
command: mongos --port 27017 --configdb ${MONGO_RS_CONFIG_NAME}/mongo-config-01:27017,mongo-config-02:27017,mongo-config-03:27017 --bind_ip_all --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_ROUTER_SERVER}-01-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ROUTER_SERVER}-01/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ROUTER_SERVER}-01/configdb:/data/configdb
mongo-router-02:
command: mongos --port 27017 --configdb ${MONGO_RS_CONFIG_NAME}/mongo-config-01:27017,mongo-config-02:27017,mongo-config-03:27017 --bind_ip_all --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_ROUTER_SERVER}-02-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ROUTER_SERVER}-02/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ROUTER_SERVER}-02/configdb:/data/configdb
# Config Servers
mongo-config-01:
command: mongod --port 27017 --configsvr --replSet ${MONGO_RS_CONFIG_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_CONFIG_SERVER}-01-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/preprod/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-01/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-01/configdb:/data/configdb
mongo-config-02:
command: mongod --port 27017 --configsvr --replSet ${MONGO_RS_CONFIG_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_CONFIG_SERVER}-02-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/preprod/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-02/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-02/configdb:/data/configdb
mongo-config-03:
command: mongod --port 27017 --configsvr --replSet ${MONGO_RS_CONFIG_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_CONFIG_SERVER}-03-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-03/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_CONFIG_SERVER}-03/configdb:/data/configdb
# Data Servers
mongo-arbiter-01:
command: mongod --port 27017 --shardsvr --replSet ${MONGO_RS_DATA_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_ARBITER_SERVER}-01-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ARBITER_SERVER}-01/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_ARBITER_SERVER}-01/configdb:/data/configdb
mongo-data-01:
command: mongod --port 27017 --shardsvr --replSet ${MONGO_RS_DATA_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_DATA_SERVER}-01-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_DATA_SERVER}-01/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_DATA_SERVER}-01/configdb:/data/configdb
mongo-data-02:
command: mongod --port 27017 --shardsvr --replSet ${MONGO_RS_DATA_NAME} --keyFile /etc/mongo-cluster.key
container_name: ${MONGO_DATA_SERVER}-02-${ENVIRONMENT_NAME}
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_ADMIN_USER}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_ADMIN_PASSWORD}
image: mongo:${MONGO_VERSION}
networks:
- mongo-network
restart: always
volumes:
- ./keys/${ENVIRONMENT_NAME}/mongo-cluster.key:/etc/mongo-cluster.key
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_DATA_SERVER}-02/db:/data/db
- ./volumes/${ENVIRONMENT_NAME}/${MONGO_DATA_SERVER}-02/configdb:/data/configdb
networks:
mongo-network:
external:
name: _preprod
Thanks in advance