Home > Blockchain >  Mongodb-express wont compose with docker-compose.yaml
Mongodb-express wont compose with docker-compose.yaml

Time:05-09

whenever i try to compose mongodb and mongodb-express i get the below error

C:\Users\ayan9\Documents\repository\ayanpal_dot_me [master  2 ~0 -0 !]> docker compose up
[ ] Running 3/3
 - Network ayanpal_dot_me_default            Created                                                                                                                                                        0.0s
 - Container ayanpal_dot_me-mongo-express-1  Created                                                                                                                                                        0.0s
 - Container ayanpal_dot_me-mongodb-1        Created                                                                                                                                                        0.0s
Attaching to ayanpal_dot_me-mongo-express-1, ayanpal_dot_me-mongodb-1
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.254 00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.255 00:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.257 00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.257 00:00"},"s":"I",  "c":"NETWORK",  "id":4648601, "ctx":"main","msg":"Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize."}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.258 00:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","ns":"config.tenantMigrationDonors"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","ns":"config.tenantMigrationRecipients"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"CONTROL",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":1,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"5924e60df736"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"5.0.8","gitVersion":"c87e1c23421bf79614baf500fda6622bd90f674e","openSSLVersion":"OpenSSL 1.1.1f  31 Mar 2020","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2004","distarch":"x86_64","target_arch":"x86_64"}}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"20.04"}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.259 00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"}}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.261 00:00"},"s":"I",  "c":"STORAGE",  "id":22297,   "ctx":"initandlisten","msg":"Using the XFS filesystem is strongly recommended with the WiredTiger storage engine. See http://dochub.mongodb.org/core/prodnotes-filesystem","tags":["startupWarnings"]}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.261 00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=15474M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),builtin_extension_config=(zstd=(compression_level=6)),file_manager=(close_idle_time=600,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress,compact_progress],"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.681 00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1652017564:681852][1:0x7ff209735c80], txn-recover: [WT_VERB_RECOVERY_ALL] Set global recovery timestamp: (0, 0)"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.681 00:00"},"s":"I",  "c":"STORAGE",  "id":22430,   "ctx":"initandlisten","msg":"WiredTiger message","attr":{"message":"[1652017564:681919][1:0x7ff209735c80], txn-recover: [WT_VERB_RECOVERY_ALL] Set global oldest timestamp: (0, 0)"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.690 00:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":429}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.690 00:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.704 00:00"},"s":"I",  "c":"STORAGE",  "id":4366408, "ctx":"initandlisten","msg":"No table logging settings modifications are required for existing WiredTiger tables","attr":{"loggingEnabled":true}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.704 00:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.714 00:00"},"s":"W",  "c":"CONTROL",  "id":22120,   "ctx":"initandlisten","msg":"Access control is not enabled for the database. Read and write access to data and configuration is unrestricted","tags":["startupWarnings"]}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.714 00:00"},"s":"W",  "c":"CONTROL",  "id":22178,   "ctx":"initandlisten","msg":"/sys/kernel/mm/transparent_hugepage/enabled is 'always'. We suggest setting it to 'never'","tags":["startupWarnings"]}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.715 00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"1b6aefca-c53e-42d0-9c9b-d2e8eee30340"}},"options":{"uuid":{"$uuid":"1b6aefca-c53e-42d0-9c9b-d2e8eee30340"}}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.728 00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"admin.system.version","index":"_id_","commitTimestamp":null}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.729 00:00"},"s":"I",  "c":"REPL",     "id":20459,   "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"5.0"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.729 00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":13},"outgoing":{"minWireVersion":0,"maxWireVersion":13},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":13,"maxWireVersion":13},"outgoing":{"minWireVersion":13,"maxWireVersion":13},"isInternalClient":true}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.729 00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":13,"maxWireVersion":13},"outgoing":{"minWireVersion":13,"maxWireVersion":13},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":13},"incomingInternalClient":{"minWireVersion":13,"maxWireVersion":13},"outgoing":{"minWireVersion":13,"maxWireVersion":13},"isInternalClient":true}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.729 00:00"},"s":"I",  "c":"STORAGE",  "id":5071100, "ctx":"initandlisten","msg":"Clearing temp directory"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.729 00:00"},"s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.730 00:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.730 00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"local.startup_log","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"b0eb7b0e-af74-4183-8a67-ecd9e7de29cc"}},"options":{"capped":true,"size":10485760}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.743 00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"local.startup_log","index":"_id_","commitTimestamp":null}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.744 00:00"},"s":"I",  "c":"REPL",     "id":6015317, "ctx":"initandlisten","msg":"Setting new configuration state","attr":{"newState":"ConfigReplicationDisabled","oldState":"ConfigPreStart"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.745 00:00"},"s":"I",  "c":"CONTROL",  "id":20712,   "ctx":"LogicalSessionCacheReap","msg":"Sessions collection is not set up; waiting until next sessions reap interval","attr":{"error":"NamespaceNotFound: config.system.sessions does not exist"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.745 00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.745 00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.745 00:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.745 00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"LogicalSessionCacheRefresh","msg":"createCollection","attr":{"namespace":"config.system.sessions","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"12df9af9-6392-49ea-abe2-84b860973329"}},"options":{}}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.763 00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"_id_","commitTimestamp":null}}
ayanpal_dot_me-mongodb-1        | {"t":{"$date":"2022-05-08T13:46:04.763 00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"namespace":"config.system.sessions","index":"lsidTTLIndex","commitTimestamp":null}}
ayanpal_dot_me-mongo-express-1  | Welcome to mongo-express
ayanpal_dot_me-mongo-express-1  | ------------------------
ayanpal_dot_me-mongo-express-1  |
ayanpal_dot_me-mongo-express-1  |
ayanpal_dot_me-mongo-express-1  | (node:7) [MONGODB DRIVER] Warning: Current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
ayanpal_dot_me-mongo-express-1  | Could not connect to database using connectionString: mongodb://mongo:27017"
ayanpal_dot_me-mongo-express-1  | (node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: getaddrinfo EAI_AGAIN mongo
ayanpal_dot_me-mongo-express-1  |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) {
ayanpal_dot_me-mongo-express-1  |   name: 'MongoNetworkError'
ayanpal_dot_me-mongo-express-1  | }]
ayanpal_dot_me-mongo-express-1  |     at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)
ayanpal_dot_me-mongo-express-1  |     at Pool.emit (events.js:314:20)
ayanpal_dot_me-mongo-express-1  |     at /node_modules/mongodb/lib/core/connection/pool.js:564:14
ayanpal_dot_me-mongo-express-1  |     at /node_modules/mongodb/lib/core/connection/pool.js:1000:11
ayanpal_dot_me-mongo-express-1  |     at /node_modules/mongodb/lib/core/connection/connect.js:32:7
ayanpal_dot_me-mongo-express-1  |     at callback (/node_modules/mongodb/lib/core/connection/connect.js:300:5)
ayanpal_dot_me-mongo-express-1  |     at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connect.js:330:7)
ayanpal_dot_me-mongo-express-1  |     at Object.onceWrapper (events.js:421:26)
ayanpal_dot_me-mongo-express-1  |     at Socket.emit (events.js:314:20)
ayanpal_dot_me-mongo-express-1  |     at emitErrorNT (internal/streams/destroy.js:92:8)
ayanpal_dot_me-mongo-express-1  |     at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
ayanpal_dot_me-mongo-express-1  |     at processTicksAndRejections (internal/process/task_queues.js:84:21)
ayanpal_dot_me-mongo-express-1  | (node:7) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
ayanpal_dot_me-mongo-express-1  | (node:7) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
ayanpal_dot_me-mongo-express-1 exited with code 0

My docker-compose.yaml is as below

services:
  mongodb:
    image: mongo
    environment:
      - MONGO_INTIDB_ROOT_USERNAME=rootuser
      - MONGO_INTIDB_ROOT_PASSOWRD=rootpass
  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
      - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass

Just trying to run mongodb and mongodb express via docker I have tried adding the ports to both the server configs of mongodb and mongodb-express also added the volumes and networks but this error is very confusing

CodePudding user response:

There are two issues. The first is that Express tries to connect to the database using a default hostname of 'mongo'. Yours is called 'mongodb' so it can't find it. The easiest way to fix this is by naming the service mongo rather than mongodb.

Now mongo-express can find the mongo container, but now the second issue arises: The mongo-express container tries to connect to the mongo database immediately after startup, but the mongo database isn't ready to accept connections at that time. An easy way around that is to set the restart option to always, so the container restarts until it succeeds.

Try this

version: '3.9'
services:
  mongo:
    image: mongo
    environment:
      - MONGO_INTIDB_ROOT_USERNAME=rootuser
      - MONGO_INTIDB_ROOT_PASSOWRD=rootpass
  mongo-express:
    image: mongo-express
    ports:
      - 8081:8081
    environment:
      - ME_CONFIG_MONGODB_ADMINUSERNAME=rootuser
      - ME_CONFIG_MONGODB_ADMINPASSWORD=rootpass
    restart: always
    depends_on:
      - mongo
  • Related