docker-library / mongo

Docker Official Image packaging for MongoDB
https://www.mongodb.org/
Apache License 2.0
1.03k stars 623 forks source link

Cannot create sharded cluster from version 5.0 #644

Open zpatekar opened 1 year ago

zpatekar commented 1 year ago

Hello, I'm having issues on upgrading local sharded cluster from version 4.4 to 5. For example, Dockerfile for config and shard servers looks like this:

FROM mongo:5.0.21
COPY key /key
COPY scripts /scripts
RUN chown -R mongodb /key
RUN chown -R mongodb /scripts

Docker-compose.yml:

  ...
  mongo_config:
    build: ../mongo-cluster/image
    container_name: mongo_config
    command: mongod --port 27017 --configsvr --replSet configserver --keyFile /key/mongodb.key
    env_file:
      - ../mongo-cluster/mongo-credentials.env
    ...

Issue is in docker-entrypoint.sh where the script removes --replSet switch when trying to start un-authenticated mongod version to add root user and password provided in the environment file. The error presented is: BadValue: Cannot start a configsvr as a standalone server. Please use the option --replset to start the node as a replica set. It should remove both --configsvr and --shardsvr switches, plus add --dbPath switch because config server uses a different path. When I try adding this options everything works. Additions are:

  1. __mongod_hack_ensure_noarg --configsvr "${mongodHackedArgs[@]}" (line 318)
  2. __mongod_hack_ensure_noarg --shardsvr "${mongodHackedArgs[@]}" (line 319)
  3. __mongod_hack_ensure_arg_val --dbpath "$(dbPath "$@")" "${mongodHackedArgs[@]}" (line 344)

    Is this something that can be added/modified officially?

yosifkit commented 1 year ago

I have a PR for this, https://github.com/docker-library/mongo/pull/600, but wasn't certain if it was good enough.

Related to https://github.com/docker-library/mongo/issues/509

zpatekar commented 1 year ago

I see that your PR already has one part solved, and the same issue applies to the shard server initial startup. I would really appreciate these changes going in officially, what would be the best path to take here? Can you update your PR to include the change I proposed above?

theDanielJLewis commented 5 days ago

Any solutions, yet?