I am try to create Mongo Replication on Docker
// docker-compose.yml
version: "3.6"
services:
mongo-rs0:
hostname: mongo-rs0
container_name: mongo-rs0
image: mongo:4.2.0
ports:
- 4200:27017
networks:
- mongo-cluster
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- /data/volume-mongo-rs/db-rs0:/data/db
- /data/volume-mongo-rs/mongod-rs0.conf:/etc/mongod.conf
- /data/volume-mongo-rs/mongo.key:/etc/mongo.key
command: >
--config /etc/mongod.conf
--replSet mongo-set
--keyFile /etc/mongo.key
--auth
mongo-rs1:
hostname: mongo-rs1
container_name: mongo-rs1
image: mongo:4.2.0
ports:
- 4201:27017
networks:
- mongo-cluster
restart: always
volumes:
- /data/volume-mongo-rs/db-rs1:/data/db
- /data/volume-mongo-rs/mongod-rs1.conf:/etc/mongod.conf
- /data/volume-mongo-rs/mongo.key:/etc/mongo.key
depends_on:
- mongo-rs0
command: >
--config /etc/mongod.conf
--replSet mongo-set
--keyFile /etc/mongo.key
mongo-rs2:
hostname: mongo-rs2
container_name: mongo-rs2
image: mongo:4.2.0
ports:
- 4202:27017
networks:
- mongo-cluster
restart: always
volumes:
- /data/volume-mongo-rs/db-rs2:/data/db
- /data/volume-mongo-rs/mongod-rs2.conf:/etc/mongod.conf
- /data/volume-mongo-rs/mongo.key:/etc/mongo.key
depends_on:
- mongo-rs0
command: >
--config /etc/mongod.conf
--replSet mongo-set
--keyFile /etc/mongo.key
networks:
mongo-cluster:
driver: bridge
name: mongo-cluster
Then run docker-compose up
, and config replication.
docker exec -it mongo-rs0 bash
> mongo -u root -p password
> rs.initiate(......)
......
> rs.status()
----
{
"set" : "mongo-set",
"date" : ISODate("2019-09-23T04:35:53.048Z"),
"myState" : 1,
"term" : NumberLong(2),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"lastCommittedWallTime" : ISODate("2019-09-23T04:35:43.089Z"),
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"readConcernMajorityWallTime" : ISODate("2019-09-23T04:35:43.089Z"),
"appliedOpTime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"durableOpTime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"lastAppliedWallTime" : ISODate("2019-09-23T04:35:43.089Z"),
"lastDurableWallTime" : ISODate("2019-09-23T04:35:43.089Z")
},
"lastStableRecoveryTimestamp" : Timestamp(1569213313, 1),
"lastStableCheckpointTimestamp" : Timestamp(1569213313, 1),
"members" : [
{
"_id" : 0,
"name" : "mongo-rs0:27017",
"ip" : "172.21.0.2",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 1671,
"optime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2019-09-23T04:35:43Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"electionTime" : Timestamp(1569211711, 1),
"electionDate" : ISODate("2019-09-23T04:08:31Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "mongo-rs1:27017",
"ip" : "172.21.0.4",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1646,
"optime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"optimeDurable" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2019-09-23T04:35:43Z"),
"optimeDurableDate" : ISODate("2019-09-23T04:35:43Z"),
"lastHeartbeat" : ISODate("2019-09-23T04:35:52.170Z"),
"lastHeartbeatRecv" : ISODate("2019-09-23T04:35:52.169Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "mongo-rs0:27017",
"syncSourceHost" : "mongo-rs0:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "mongo-rs2:27017",
"ip" : "172.21.0.3",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 1645,
"optime" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"optimeDurable" : {
"ts" : Timestamp(1569213343, 1),
"t" : NumberLong(2)
},
"optimeDate" : ISODate("2019-09-23T04:35:43Z"),
"optimeDurableDate" : ISODate("2019-09-23T04:35:43Z"),
"lastHeartbeat" : ISODate("2019-09-23T04:35:52.169Z"),
"lastHeartbeatRecv" : ISODate("2019-09-23T04:35:52.167Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "mongo-rs0:27017",
"syncSourceHost" : "mongo-rs0:27017",
"syncSourceId" : 0,
"infoMessage" : "",
"configVersion" : 1
}
],
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1569213343, 1),
"signature" : {
"hash" : BinData(0,"V6DIc9dX91+8HcZpBFqWcp/iRmI="),
"keyId" : NumberLong("6739704750087864322")
}
},
"operationTime" : Timestamp(1569213343, 1)
}
It work fine, when I try to access mongo-rs0, -1, -2
docker container via Mongo IDE (by individual).
Finally I tried to run Meteor
with Mongo Replication on Docker
// package.json
"scripts": {
"start": "MONGO_URL='mongodb://root:password@localhost:4200,localhost:4201,localhost:4202/meteor?authSource=admin&replicaSet=mongo-set' meteor run",
},
Get error
/Users/theara/.meteor/packages/meteor-tool/.1.8.2-rc.1.4ilb91.vw5qb++os.osx.x86_64+web.browser+web.browser.legacy+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:313
W20190923-11:40:48.837(7)? (STDERR) throw(ex);
W20190923-11:40:48.838(7)? (STDERR) ^
W20190923-11:40:48.838(7)? (STDERR)
W20190923-11:40:48.839(7)? (STDERR) MongoNetworkError: failed to connect to server [mongo-rs2:27017] on first connect [MongoNetworkError: getaddrinfo ENOTFOUND mongo-rs2 mongo-rs2:27017]
W20190923-11:40:48.839(7)? (STDERR) at Pool.<anonymous> (/Users/theara/.meteor/packages/npm-mongo/.3.2.0-rc182.1.1h5gp08.oork++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/topologies/server.js:431:11)
W20190923-11:40:48.840(7)? (STDERR) at emitOne (events.js:116:13)
W20190923-11:40:48.841(7)? (STDERR) at Pool.emit (events.js:211:7)
W20190923-11:40:48.841(7)? (STDERR) at connect (/Users/theara/.meteor/packages/npm-mongo/.3.2.0-rc182.1.1h5gp08.oork++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/pool.js:557:14)
W20190923-11:40:48.841(7)? (STDERR) at makeConnection (/Users/theara/.meteor/packages/npm-mongo/.3.2.0-rc182.1.1h5gp08.oork++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/connect.js:39:11)
W20190923-11:40:48.841(7)? (STDERR) at callback (/Users/theara/.meteor/packages/npm-mongo/.3.2.0-rc182.1.1h5gp08.oork++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/connect.js:261:5)
W20190923-11:40:48.842(7)? (STDERR) at Socket.err (/Users/theara/.meteor/packages/npm-mongo/.3.2.0-rc182.1.1h5gp08.oork++os+web.browser+web.browser.legacy+web.cordova/npm/node_modules/mongodb-core/lib/connection/connect.js:286:7)
W20190923-11:40:48.842(7)? (STDERR) at Object.onceWrapper (events.js:315:30)
W20190923-11:40:48.842(7)? (STDERR) at emitOne (events.js:116:13)
Please help me???