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
{{ message }}
Repository navigation
Can't connect to Mongo instance after initialization of replica set #249
In this case, java-app is able to connect to mongo container. But I need to run mongo with --replSet argument to get mongo-connector working, so I've added this argument using command option:
After that my application is still able to connect to the instance, but mongo-connector doesn't work since replica set is not initiated. To initiate replica set, I've changed command:
mongo_1 | 2018-03-03T20:59:31.464+0000 I CONTROL [initandlisten] MongoDB starting : pid=6 port=27017 dbpath=/data/db 64-bit host=7751d36e0b39
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] db version v3.6.3
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] git version: 9586e557d54ef70f9ca4b43c26892cd55257e1a5
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1t 3 May 2016
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] allocator: tcmalloc
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] modules: none
mongo_1 | 2018-03-03T20:59:31.465+0000 I CONTROL [initandlisten] build environment:
mongo_1 | 2018-03-03T20:59:31.466+0000 I CONTROL [initandlisten] distmod: debian81
mongo_1 | 2018-03-03T20:59:31.466+0000 I CONTROL [initandlisten] distarch: x86_64
mongo_1 | 2018-03-03T20:59:31.466+0000 I CONTROL [initandlisten] target_arch: x86_64
mongo_1 | 2018-03-03T20:59:31.466+0000 I CONTROL [initandlisten] options: { replication: { replSet: "rs0" } }
mongo_1 | 2018-03-03T20:59:31.466+0000 W - [initandlisten] Detected unclean shutdown - /data/db/mongod.lock is not empty.
mongo_1 | 2018-03-03T20:59:31.467+0000 I - [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongo_1 | 2018-03-03T20:59:31.467+0000 W STORAGE [initandlisten] Recovering data from the last clean checkpoint.
mongo_1 | 2018-03-03T20:59:31.468+0000 I STORAGE [initandlisten]
mongo_1 | 2018-03-03T20:59:31.468+0000 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
mongo_1 | 2018-03-03T20:59:31.468+0000 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem
mongo_1 | 2018-03-03T20:59:31.469+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=2466M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
mongo_1 | 2018-03-03T20:59:33.438+0000 I STORAGE [initandlisten] WiredTiger message [1520110773:438769][6:0x7fa96e15fa00], txn-recover: Main recovery loop: starting at 1/0
mongo_1 | 2018-03-03T20:59:33.439+0000 I STORAGE [initandlisten] WiredTiger message [1520110773:439805][6:0x7fa96e15fa00], txn-recover: Recovering log 1 through 2
mongo_1 | 2018-03-03T20:59:33.554+0000 I STORAGE [initandlisten] WiredTiger message [1520110773:554470][6:0x7fa96e15fa00], file:index-7--5161945408363194477.wt, txn-recover: Recovering log 2 through 2
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten]
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten]
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
mongo_1 | 2018-03-03T20:59:33.736+0000 I CONTROL [initandlisten]
mongo_1 | 2018-03-03T20:59:33.772+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongo_1 | 2018-03-03T20:59:33.778+0000 I REPL [initandlisten] Did not find local voted for document at startup.
mongo_1 | 2018-03-03T20:59:33.780+0000 I REPL [initandlisten] Did not find local replica set configuration document at startup; NoMatchingDocument: Did not find replica set configuration document in local.system.replset
mongo_1 | 2018-03-03T20:59:33.783+0000 I NETWORK [initandlisten] waiting for connections on port 27017
mongo_1 | 2018-03-03T20:59:34.024+0000 I FTDC [ftdc] Unclean full-time diagnostic data capture shutdown detected, found interim file, some metrics may have been lost. OK
This will never get to the mongo admin side until the mongod server stops. You need to run the rs.initiate(); separately from the mongo server process. The hacky way is to run something in the background and then start mongod in the foreground.
#!/bin/bash# untested, very hacky# set this script as your "entrypoint" and then command: ["--replSet", "rs0"]set -e
# Sleep for 30 and then create the replica set
{ sleep 30 && mongo admin --eval 'rs.initiate();' } &exec docker-entrypoint.sh "$@"
The less hacky is to use another process that uses service discovery so that you can ensure that you only initiate on the first server and then to join other nodes to the replica set.
This will never get to the mongo admin side until the mongod server stops. You need to run the rs.initiate(); separately from the mongo server process. The hacky way is to run something in the background and then start mongod in the foreground.
#!/bin/bash# untested, very hacky# set this script as your "entrypoint" and then command: ["--replSet", "rs0"]set -e
# Sleep for 30 and then create the replica set
{ sleep 30 && mongo admin --eval 'rs.initiate();' } &exec docker-entrypoint.sh "$@"
The less hacky is to use another process that uses service discovery so that you can ensure that you only initiate on the first server and then to join other nodes to the replica set.
I tried that but it is not working: even after substituting the curly brackets with the round ones (otherwise reporting a syntax error), after the 30 seconds, I get prompted MongoDB shell version v4.2.6 continuously until my PC gets stuck.
Can you please try the script and tell me if it is working on your side? Thanks.
Activity
myashchenko commentedon Mar 4, 2018
Output:
yosifkit commentedon Apr 17, 2018
This will never get to the
mongo adminside until themongodserver stops. You need to run thers.initiate();separately from the mongo server process. The hacky way is to run something in the background and then start mongod in the foreground.The less hacky is to use another process that uses service discovery so that you can ensure that you only initiate on the first server and then to join other nodes to the replica set.
In the future, it'd be better to post questions like this in the Docker Community Forums, the Docker Community Slack, or Stack Overflow.
eloparco commentedon Apr 28, 2020
I tried that but it is not working: even after substituting the curly brackets with the round ones (otherwise reporting a syntax error), after the 30 seconds, I get prompted
MongoDB shell version v4.2.6continuously until my PC gets stuck.Can you please try the script and tell me if it is working on your side? Thanks.