mongo icon indicating copy to clipboard operation
mongo copied to clipboard

mongo:5.0.3 - Failed to run container with initdb

Open Ap4uPNZ opened this issue 2 years ago • 2 comments

Step to reproduce docker run --rm -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=root mongo:5.0.3 mongod --shardsvr --replSet a or docker run --rm -e MONGO_INITDB_ROOT_USERNAME=root -e MONGO_INITDB_ROOT_PASSWORD=root mongo:5.0.3 mongod --configsvr --replSet a

Actual result

BadValue: Cannot start a shardsvr as a standalone server. Please use the option --replset to start the node as a replica set.
try 'mongod --help' for more information

Starts from 5.0.3 mongod requires replica set for shardsvr or configsvr cluster role (issue - https://jira.mongodb.org/browse/SERVER-27383)

It is caused by this code: https://github.com/docker-library/mongo/blob/master/5.0/docker-entrypoint.sh#L286

Ap4uPNZ avatar Nov 12 '21 12:11 Ap4uPNZ

  1. it doesn't make sense to try to add an admin user/pass to a shard server, since they don't store the admin database (that's on the config server). It also doesn't make sense to try to run any scripts in /docker-entrypoint-initdb.d/, since, as far as I understand it, you need to go through a mongos server in order to talk to a sharded cluster.
    • so, we should probably adjust the entrypoint script to either warn & ignore if any of that is attempted on a shardsvr or just error out if they are supplied with shardsvr
  2. as for user/pass with configsvr, that still works for 4.4, but replica set being required in 5.0 complicates things.
    • since replSet does not work correctly on the temporary mongod server, we should also remove configsvr but preserve its default dbPath for the temporary mongod server so that data is in the correct location

yosifkit avatar Nov 13 '21 01:11 yosifkit

Finally have a PR to address the configsvr half of this issue: https://github.com/docker-library/mongo/pull/600.

yosifkit avatar Jan 21 '23 00:01 yosifkit