When I run docker-compose -f mongo-services.yaml up
to compose this file below:
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: supersecret
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
ME_CONFIG_MONGODB_ADMINPASSWORD: supersecret
ME_CONFIG_MONGODB_SERVER: mongo
depends_on:
- "mongodb"
I tried to compose
this file. I expected the mongo-express
to connect the mongodb
which it did for a split 30’s then it continually disconnects as it shows.
Could not connect to database using connectionString: mongodb://admin:****@mongo:27017/"
mongo-express-1 | /app/node_modules/mongodb/lib/sdam/topology.js:285
mongo-express-1 | const timeoutError = new error_1.MongoServerSelectionError(`Server selection timed out after ${serverSelectionTimeoutMS} ms`, this.description);
mongodb-1 | {"t":{"$date":"2024-09-10T16:35:53.056+00:00"},"s":"I", "c":"WTCHKPT", "id":22430, "ctx":"Checkpointer","msg":"WiredTiger message","attr":{"message":{"ts_sec":1725986153,"ts_usec":56936,"thread":"1:0x7ff8cf000640","session_name":"WT_SESSION.checkpoint","category":"WT_VERB_CHECKPOINT_PROGRESS","category_id":6,"verbose_level":"DEBUG_1","verbose_level_id":1,"msg":"saving checkpoint snapshot min: 4, snapshot max: 4 snapshot count: 0, oldest timestamp: (0, 0) , meta checkpoint timestamp: (0, 0) base write gen: 7"}}}
The mongodb service (thus, host name for the compose) is called mongodb
, not mongo
, so change this:
ME_CONFIG_MONGODB_SERVER: mongo
to:
ME_CONFIG_MONGODB_SERVER: mongodb
4