You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to create a MongoDB instance with --replSet using Docker compose.
Expected outcome:mongod is started with --replSet and rs.initiate() executes successfully.
Observed outcome:rs.initiate() fails with the error This node was not started with the replSet option.
Reading docker-entrypoint.sh it appears thatmongod is not started with the supplied command arguments for initialization, causing rs.initiate() to fail.
Attaching to the Docker container shows that mongodis eventually started with --replSet as specified in the docker-compose.yml file (as expected from the contents of docker-entrypoint.sh), and rs.initiate() succeeds. However this requires manual intervention to successfully initiate the replica set.
I believe this issue is distinct from #223 and #249. Though it may be due to me misusing the /docker-entrypoint-initdb.d facility for unintended purposes.
If I am correctly interpreting the order of execution in docker-entrypoint.sh, the issue appears to be due to the fact that mongod is not started with command arguments from the docker-compose file until after scripts are executed from /docker-entrypoint-initdb.d
Can you advise me on the correct order to set up MongoDB with replica sets enabled? I cannot figure out how to accomplish this with the current docker-entrypoint.sh. It does not seem to be enough that mongod is started with --replSet, if rs.initiate() is not executed:
$ docker exec -it compose-mongo_mongo_1 bash
root@e3b1725803eb:/# ps ax
PID TTY STAT TIME COMMAND
1 ? Ssl 0:00 mongod --replSet rs0 --auth --bind_ip_all
root@e3b1725803eb:/# mongo -u $MONGO_INITDB_ROOT_USERNAME -p $MONGO_INITDB_ROOT_PASSWORD admin
MongoDB shell version v4.0.10
connecting to: mongodb://127.0.0.1:27017/admin?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("5156098c-0c8f-41c0-a8d7-4d8c0b9abff3") }
MongoDB server version: 4.0.10
Welcome to the MongoDB shell.
> rs.status()
{
"ok" : 0,
"errmsg" : "no replset config has been received",
"code" : 94,
"codeName" : "NotYetInitialized"
}
More detailed information about my environment.
Here is the contents of my docker-compose.yml file:
#339 (comment)
The docker-entrypoint-initdb.d scripts run during an initialization period (and only if the database is empty), during which the container is only listening on localhost so trying to initiate a cluster during that period isn't possible as it won't resolve it's own container hostname.
Hello,
I am trying to create a MongoDB instance with
--replSet
using Docker compose.Expected outcome:
mongod
is started with--replSet
andrs.initiate()
executes successfully.Observed outcome:
rs.initiate()
fails with the errorThis node was not started with the replSet option
.Reading
docker-entrypoint.sh
it appears thatmongod
is not started with the suppliedcommand
arguments for initialization, causingrs.initiate()
to fail.Attaching to the Docker container shows that
mongod
is eventually started with--replSet
as specified in thedocker-compose.yml
file (as expected from the contents ofdocker-entrypoint.sh
), andrs.initiate()
succeeds. However this requires manual intervention to successfully initiate the replica set.I believe this issue is distinct from #223 and #249. Though it may be due to me misusing the
/docker-entrypoint-initdb.d
facility for unintended purposes.If I am correctly interpreting the order of execution in
docker-entrypoint.sh
, the issue appears to be due to the fact thatmongod
is not started withcommand
arguments from the docker-compose file until after scripts are executed from/docker-entrypoint-initdb.d
mongod
is started:mongo/4.0/docker-entrypoint.sh
Line 276 in c93d83e
Script execution from
/docker-entrypoint-initdb.d
:mongo/4.0/docker-entrypoint.sh
Line 318 in c93d83e
mongod
is started with arguments fromcommand
:mongo/4.0/docker-entrypoint.sh
Line 354 in c93d83e
Can you advise me on the correct order to set up MongoDB with replica sets enabled? I cannot figure out how to accomplish this with the current
docker-entrypoint.sh
. It does not seem to be enough thatmongod
is started with--replSet
, ifrs.initiate()
is not executed:More detailed information about my environment.
Here is the contents of my
docker-compose.yml
file:./deploy/mongodb
contains00_init_replSet.sh
which has the following:When I execute
docker-compose up
I receive the following error:I attach to the running container to check that
mongod
was started with the--replSet
option, as specified indocker-compose.yml
, and it is:If I then execute the contents of the script
/docker-entrypoint-initdb.d/00_init_replSet.sh
the replica set is successfully initiated:The following output is seen in the shell running
docker-compose up
:The text was updated successfully, but these errors were encountered: