docker-library / mongo

Docker Official Image packaging for MongoDB
https://www.mongodb.org/
Apache License 2.0
1.03k stars 619 forks source link

MONGO_INITDB_DATABASE not working #641

Closed redabourial closed 11 months ago

redabourial commented 1 year ago

Here is my docker-compose file :

version: "3"

services:
  meteor:
    build:
      context: ./conwaysgame
    volumes:
      - ./conwaysgame:/usr/src/app
    env_file: .env
    links:
      - mongo

  mongo:
    image: 'mongo:7.0'
    volumes:
      - ./db/mongo:/data/db
    env_file: .env

  mongoexpress:
    image: mongo-express
    links:
      - mongo
    depends_on:
      - mongo
    env_file: .env

my .env \:

MONGODB_INITDB_ROOT_USERNAME=root
MONGODB_INITDB_ROOT_PASSWORD=ToHTsg3eChI2oSyTEpNuWwDOT8woSljN
MONGO_INITDB_DATABASE=project

MONGO_URL=mongodb://root:ToHTsg3eChI2oSyTEpNuWwDOT8woSljN@mongo:27017/project

ME_CONFIG_MONGODB_SERVER=mongo
ME_CONFIG_MONGODB_ENABLE_ADMIN=true
ME_CONFIG_MONGODB_ADMINUSERNAME=root
ME_CONFIG_MONGODB_ADMINPASSWORD=ToHTsg3eChI2oSyTEpNuWwDOT8woSljN
ME_CONFIG_BASICAUTH_USERNAME=admin
ME_CONFIG_BASICAUTH_PASSWORD=aiwai3Eeyahc5Sai9Zee3bai1Aith1aechaejiebariu4ohcie0CooveiV8yi6ai

mongo-express logs :

Welcome to mongo-express
------------------------

(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.
Could not connect to database using connectionString: mongodb://root:ToHTsg3eChI2oSyTEpNuWwDOT8woSljN@mongo:27017/"
(node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [MongoError: Authentication failed.
    at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:19)
    at Connection.emit (events.js:314:20)
    at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
    at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23) {
  ok: 0,
  code: 18,
  codeName: 'AuthenticationFailed'
}]
    at Pool.<anonymous> (/node_modules/mongodb/lib/core/topologies/server.js:441:11)
    at Pool.emit (events.js:314:20)
    at /node_modules/mongodb/lib/core/connection/pool.js:564:14
    at /node_modules/mongodb/lib/core/connection/pool.js:1000:11
    at callback (/node_modules/mongodb/lib/core/connection/connect.js:75:5)
    at /node_modules/mongodb/lib/core/connection/connect.js:158:27
    at /node_modules/mongodb/lib/core/auth/scram.js:110:14
    at _callback (/node_modules/mongodb/lib/core/connection/connection.js:333:7)
    at Connection.messageHandler (/node_modules/mongodb/lib/core/connection/connection.js:364:9)
    at Connection.emit (events.js:314:20)
    at processMessage (/node_modules/mongodb/lib/core/connection/connection.js:456:10)
    at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connection.js:625:15)
    at Socket.emit (events.js:314:20)
    at addChunk (_stream_readable.js:297:12)
    at readableAddChunk (_stream_readable.js:272:9)
    at Socket.Readable.push (_stream_readable.js:213:10)
(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)
(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.

and mongo db logs :

{"t":{"$date":"2023-09-04T13:57:37.961+00:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"main","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":21},"outgoing":{"minWireVersion":6,"maxWireVersion":21},"isInternalClient":true}}}
{"t":{"$date":"2023-09-04T13:57:37.962+00:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2023-09-04T13:57:37.963+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."}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"main","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"CONTROL",  "id":5945603, "ctx":"main","msg":"Multi threading initialized"}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"TENANT_M", "id":7091600, "ctx":"main","msg":"Starting TenantMigrationAccessBlockerRegistry"}
{"t":{"$date":"2023-09-04T13:57:37.964+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":"b1323a34dbf3"}}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"7.0.0","gitVersion":"37d84072b5c5b9fd723db5fa133fb202ad2317f1","openSSLVersion":"OpenSSL 3.0.2 15 Mar 2022","modules":[],"allocator":"tcmalloc","environment":{"distmod":"ubuntu2204","distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Ubuntu","version":"22.04"}}}
{"t":{"$date":"2023-09-04T13:57:37.964+00:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"bindIp":"*"}}}}
{"t":{"$date":"2023-09-04T13:57:37.965+00:00"},"s":"I",  "c":"STORAGE",  "id":22315,   "ctx":"initandlisten","msg":"Opening WiredTiger","attr":{"config":"create,cache_size=14387M,session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,remove=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=2000),statistics_log=(wait=0),json_output=(error,message),verbose=[recovery_progress:1,checkpoint_progress:1,compact_progress:1,backup:0,checkpoint:0,compact:0,evict:0,history_store:0,recovery:0,rts:0,salvage:0,tiered:0,timestamp:0,transaction:0,verify:0,log:0],"}}
{"t":{"$date":"2023-09-04T13:57:38.208+00:00"},"s":"I",  "c":"STORAGE",  "id":4795906, "ctx":"initandlisten","msg":"WiredTiger opened","attr":{"durationMillis":243}}
{"t":{"$date":"2023-09-04T13:57:38.208+00:00"},"s":"I",  "c":"RECOVERY", "id":23987,   "ctx":"initandlisten","msg":"WiredTiger recoveryTimestamp","attr":{"recoveryTimestamp":{"$timestamp":{"t":0,"i":0}}}}
{"t":{"$date":"2023-09-04T13:57:38.274+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"]}
{"t":{"$date":"2023-09-04T13:57:38.274+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"]}
{"t":{"$date":"2023-09-04T13:57:38.274+00:00"},"s":"W",  "c":"CONTROL",  "id":5123300, "ctx":"initandlisten","msg":"vm.max_map_count is too low","attr":{"currentValue":65530,"recommendedMinimum":1677720,"maxConns":838860},"tags":["startupWarnings"]}
{"t":{"$date":"2023-09-04T13:57:38.274+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"admin.system.version","uuidDisposition":"provided","uuid":{"uuid":{"$uuid":"ff45f728-7b04-43e8-bd57-2644c45d4935"}},"options":{"uuid":{"$uuid":"ff45f728-7b04-43e8-bd57-2644c45d4935"}}}}
{"t":{"$date":"2023-09-04T13:57:38.307+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"ff45f728-7b04-43e8-bd57-2644c45d4935"}},"namespace":"admin.system.version","index":"_id_","ident":"index-1--4009999625461418637","collectionIdent":"collection-0--4009999625461418637","commitTimestamp":null}}
{"t":{"$date":"2023-09-04T13:57:38.307+00:00"},"s":"I",  "c":"REPL",     "id":20459,   "ctx":"initandlisten","msg":"Setting featureCompatibilityVersion","attr":{"newVersion":"7.0"}}
{"t":{"$date":"2023-09-04T13:57:38.307+00:00"},"s":"I",  "c":"REPL",     "id":5853300, "ctx":"initandlisten","msg":"current featureCompatibilityVersion value","attr":{"featureCompatibilityVersion":"7.0","context":"setFCV"}}
{"t":{"$date":"2023-09-04T13:57:38.307+00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":21},"outgoing":{"minWireVersion":6,"maxWireVersion":21},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true}}}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"NETWORK",  "id":4915702, "ctx":"initandlisten","msg":"Updated wire specification","attr":{"oldSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true},"newSpec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":21},"incomingInternalClient":{"minWireVersion":21,"maxWireVersion":21},"outgoing":{"minWireVersion":21,"maxWireVersion":21},"isInternalClient":true}}}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"REPL",     "id":5853300, "ctx":"initandlisten","msg":"current featureCompatibilityVersion value","attr":{"featureCompatibilityVersion":"7.0","context":"startup"}}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"STORAGE",  "id":5071100, "ctx":"initandlisten","msg":"Clearing temp directory"}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"CONTROL",  "id":6608200, "ctx":"initandlisten","msg":"Initializing cluster server parameters from disk"}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"CONTROL",  "id":20536,   "ctx":"initandlisten","msg":"Flow Control is enabled on this deployment"}
{"t":{"$date":"2023-09-04T13:57:38.308+00:00"},"s":"I",  "c":"FTDC",     "id":20625,   "ctx":"initandlisten","msg":"Initializing full-time diagnostic data capture","attr":{"dataDirectory":"/data/db/diagnostic.data"}}
{"t":{"$date":"2023-09-04T13:57:38.310+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"initandlisten","msg":"createCollection","attr":{"namespace":"local.startup_log","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"ef3a7729-b62a-4fad-8d03-703564d939f4"}},"options":{"capped":true,"size":10485760}}}
{"t":{"$date":"2023-09-04T13:57:38.345+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"initandlisten","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"ef3a7729-b62a-4fad-8d03-703564d939f4"}},"namespace":"local.startup_log","index":"_id_","ident":"index-3--4009999625461418637","collectionIdent":"collection-2--4009999625461418637","commitTimestamp":null}}
{"t":{"$date":"2023-09-04T13:57:38.346+00:00"},"s":"I",  "c":"REPL",     "id":6015317, "ctx":"initandlisten","msg":"Setting new configuration state","attr":{"newState":"ConfigReplicationDisabled","oldState":"ConfigPreStart"}}
{"t":{"$date":"2023-09-04T13:57:38.346+00:00"},"s":"I",  "c":"STORAGE",  "id":22262,   "ctx":"initandlisten","msg":"Timestamp monitor starting"}
{"t":{"$date":"2023-09-04T13:57:38.347+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"}}
{"t":{"$date":"2023-09-04T13:57:38.347+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"/tmp/mongodb-27017.sock"}}
{"t":{"$date":"2023-09-04T13:57:38.347+00:00"},"s":"I",  "c":"NETWORK",  "id":23015,   "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
{"t":{"$date":"2023-09-04T13:57:38.347+00:00"},"s":"I",  "c":"NETWORK",  "id":23016,   "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
{"t":{"$date":"2023-09-04T13:57:38.347+00:00"},"s":"I",  "c":"STORAGE",  "id":20320,   "ctx":"LogicalSessionCacheRefresh","msg":"createCollection","attr":{"namespace":"config.system.sessions","uuidDisposition":"generated","uuid":{"uuid":{"$uuid":"110f09b3-9cd2-444a-9bd0-4a888c1f3892"}},"options":{}}}
{"t":{"$date":"2023-09-04T13:57:38.369+00:00"},"s":"I",  "c":"REPL",     "id":7360102, "ctx":"LogicalSessionCacheRefresh","msg":"Added oplog entry for create to transaction","attr":{"namespace":"config.$cmd","uuid":{"uuid":{"$uuid":"110f09b3-9cd2-444a-9bd0-4a888c1f3892"}},"object":{"create":"system.sessions","idIndex":{"v":2,"key":{"_id":1},"name":"_id_"}}}}
{"t":{"$date":"2023-09-04T13:57:38.370+00:00"},"s":"I",  "c":"REPL",     "id":7360100, "ctx":"LogicalSessionCacheRefresh","msg":"Added oplog entry for createIndexes to transaction","attr":{"namespace":"config.$cmd","uuid":{"uuid":{"$uuid":"110f09b3-9cd2-444a-9bd0-4a888c1f3892"}},"object":{"createIndexes":"system.sessions","v":2,"key":{"lastUse":1},"name":"lsidTTLIndex","expireAfterSeconds":1800}}}
{"t":{"$date":"2023-09-04T13:57:38.381+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"110f09b3-9cd2-444a-9bd0-4a888c1f3892"}},"namespace":"config.system.sessions","index":"_id_","ident":"index-5--4009999625461418637","collectionIdent":"collection-4--4009999625461418637","commitTimestamp":null}}
{"t":{"$date":"2023-09-04T13:57:38.381+00:00"},"s":"I",  "c":"INDEX",    "id":20345,   "ctx":"LogicalSessionCacheRefresh","msg":"Index build: done building","attr":{"buildUUID":null,"collectionUUID":{"uuid":{"$uuid":"110f09b3-9cd2-444a-9bd0-4a888c1f3892"}},"namespace":"config.system.sessions","index":"lsidTTLIndex","ident":"index-6--4009999625461418637","collectionIdent":"collection-4--4009999625461418637","commitTimestamp":null}}
{"t":{"$date":"2023-09-04T13:57:39.173+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.21.0.3:37704","uuid":{"uuid":{"$uuid":"8f827058-0257-4962-9351-2b4784475078"}},"connectionId":1,"connectionCount":1}}
{"t":{"$date":"2023-09-04T13:57:39.178+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn1","msg":"client metadata","attr":{"remote":"172.21.0.3:37704","client":"conn1","doc":{"driver":{"name":"nodejs","version":"3.7.3"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"6.1.0-11-amd64"},"platform":"'Node.js v12.22.7, LE (legacy)"}}}
{"t":{"$date":"2023-09-04T13:57:39.178+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn1","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":{"user":"root","db":"admin"}}}
{"t":{"$date":"2023-09-04T13:57:39.178+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn1","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:39.178+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn1","msg":"Failed to authenticate","attr":{"client":"172.21.0.3:37704","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"root","db":"admin","error":"UserNotFound: Could not find user \"root\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":201,"summary":{"0":{"step":1,"step_total":2,"duration_micros":182}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:39.181+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn1","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:39.181+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn1","msg":"Failed to authenticate","attr":{"client":"172.21.0.3:37704","isSpeculative":false,"isClusterMember":false,"mechanism":"SCRAM-SHA-1","user":"root","db":"admin","error":"UserNotFound: Could not find user \"root\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":301,"summary":{"0":{"step":1,"step_total":2,"duration_micros":279}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:39.186+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn1","msg":"Connection ended","attr":{"remote":"172.21.0.3:37704","uuid":{"uuid":{"$uuid":"8f827058-0257-4962-9351-2b4784475078"}},"connectionId":1,"connectionCount":0}}
{"t":{"$date":"2023-09-04T13:57:51.264+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.21.0.3:45608","uuid":{"uuid":{"$uuid":"01f75061-b6f0-4b24-ba28-250f8bc44777"}},"connectionId":2,"connectionCount":1}}
{"t":{"$date":"2023-09-04T13:57:51.269+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn2","msg":"client metadata","attr":{"remote":"172.21.0.3:45608","client":"conn2","doc":{"driver":{"name":"nodejs","version":"3.7.3"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"6.1.0-11-amd64"},"platform":"'Node.js v12.22.7, LE (legacy)"}}}
{"t":{"$date":"2023-09-04T13:57:51.269+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn2","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":{"user":"root","db":"admin"}}}
{"t":{"$date":"2023-09-04T13:57:51.269+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn2","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:51.270+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn2","msg":"Failed to authenticate","attr":{"client":"172.21.0.3:45608","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"root","db":"admin","error":"UserNotFound: Could not find user \"root\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":196,"summary":{"0":{"step":1,"step_total":2,"duration_micros":164}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:51.272+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn2","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:51.273+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn2","msg":"Failed to authenticate","attr":{"client":"172.21.0.3:45608","isSpeculative":false,"isClusterMember":false,"mechanism":"SCRAM-SHA-1","user":"root","db":"admin","error":"UserNotFound: Could not find user \"root\" for db \"admin\"","result":11,"metrics":{"conversation_duration":{"micros":304,"summary":{"0":{"step":1,"step_total":2,"duration_micros":276}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:51.278+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn2","msg":"Connection ended","attr":{"remote":"172.21.0.3:45608","uuid":{"uuid":{"$uuid":"01f75061-b6f0-4b24-ba28-250f8bc44777"}},"connectionId":2,"connectionCount":0}}
{"t":{"$date":"2023-09-04T13:57:57.319+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.21.0.4:51034","uuid":{"uuid":{"$uuid":"bda0ec99-1ee9-4611-820f-5787e200005f"}},"connectionId":3,"connectionCount":1}}
{"t":{"$date":"2023-09-04T13:57:57.322+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn3","msg":"client metadata","attr":{"remote":"172.21.0.4:51034","client":"conn3","doc":{"driver":{"name":"nodejs","version":"4.16.0"},"platform":"Node.js v14.21.4, LE","os":{"name":"linux","architecture":"x64","version":"6.1.0-11-amd64","type":"Linux"}}}}
{"t":{"$date":"2023-09-04T13:57:57.326+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.21.0.4:51050","uuid":{"uuid":{"$uuid":"d8cb5551-c113-414c-b6ab-03226674b650"}},"connectionId":4,"connectionCount":2}}
{"t":{"$date":"2023-09-04T13:57:57.327+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn4","msg":"client metadata","attr":{"remote":"172.21.0.4:51050","client":"conn4","doc":{"driver":{"name":"nodejs","version":"4.16.0"},"platform":"Node.js v14.21.4, LE","os":{"name":"linux","architecture":"x64","version":"6.1.0-11-amd64","type":"Linux"}}}}
{"t":{"$date":"2023-09-04T13:57:57.328+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn4","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":{"user":"root","db":"project"}}}
{"t":{"$date":"2023-09-04T13:57:57.328+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn4","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:57.328+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn4","msg":"Failed to authenticate","attr":{"client":"172.21.0.4:51050","isSpeculative":true,"isClusterMember":false,"mechanism":"SCRAM-SHA-256","user":"root","db":"project","error":"UserNotFound: Could not find user \"root\" for db \"project\"","result":11,"metrics":{"conversation_duration":{"micros":184,"summary":{"0":{"step":1,"step_total":2,"duration_micros":170}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:57.329+00:00"},"s":"I",  "c":"ACCESS",   "id":6788604, "ctx":"conn4","msg":"Auth metrics report","attr":{"metric":"acquireUser","micros":0}}
{"t":{"$date":"2023-09-04T13:57:57.330+00:00"},"s":"I",  "c":"ACCESS",   "id":5286307, "ctx":"conn4","msg":"Failed to authenticate","attr":{"client":"172.21.0.4:51050","isSpeculative":false,"isClusterMember":false,"mechanism":"SCRAM-SHA-1","user":"root","db":"project","error":"UserNotFound: Could not find user \"root\" for db \"project\"","result":11,"metrics":{"conversation_duration":{"micros":343,"summary":{"0":{"step":1,"step_total":2,"duration_micros":313}}}},"extraInfo":{}}}
{"t":{"$date":"2023-09-04T13:57:57.332+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn3","msg":"Connection ended","attr":{"remote":"172.21.0.4:51034","uuid":{"uuid":{"$uuid":"bda0ec99-1ee9-4611-820f-5787e200005f"}},"connectionId":3,"connectionCount":1}}
{"t":{"$date":"2023-09-04T13:57:57.425+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn4","msg":"Connection ended","attr":{"remote":"172.21.0.4:51050","uuid":{"uuid":{"$uuid":"d8cb5551-c113-414c-b6ab-03226674b650"}},"connectionId":4,"connectionCount":0}}

I tried connecting to the database with studio 3t with no success.

hugotkk commented 12 months ago

I experienced a similar issue. Not sure if it's your case.

I'm working with the mongo:latest image and a docker-compose.yml file, without a volume mount. At the beginning, I hadn't set a password for development.

  mongo:
    image: mongo:latest
    networks:
      - backend

But I subsequently added one to my setup. then use docker compose up -d to recreate my container

  mongo:
    image: mongo:latest
    networks:
      - backend
    environment:
        MONGO_INITDB_ROOT_USERNAME: <username>
        MONGO_INITDB_ROOT_PASSWORD: <password>

I can see the environment variables were set inside the container

Even downgrading from latest to 7.0 or 6.0, the problem didn't go away, and the latter even led to a compatibility error. It give me a hint that some persistent data are left behind.

When I remove the container with docker rm -f <container> and bring it up again, everything works fine.

LaurentGoderre commented 12 months ago

@redabourial there are two issues with the code.

First the env vars should be MONGO_INITDB_ROOT_USERNAME and MONGODB_INITDB_ROOT_PASSWORD (Note the MONGO_ not MONGODB_)

~The second one is the volume. Commenting out the - ./db/mongo:/data/db makes it work.~ It also fails if the folder db/mongo doesn't exist on the host in the same folder as the Dockerfile

redabourial commented 12 months ago

@LaurentGoderre thanks for the insight, i can connect to the admin database though (so for development purposes my issue is solved). I still don't understand why MONGO_INITDB_DATABASE doesn't have any effect. Do you have any idea why that is ?

LaurentGoderre commented 12 months ago

@redabourial you might need to modify your connection string:

mongodb://root:ToHTsg3eChI2oSyTEpNuWwDOT8woSljN@mongo:27017/project?authSource=admin
yosifkit commented 12 months ago

From the docs on Docker Hub:

MongoDB is fundamentally designed for "create on first use", so if you do not insert data with your JavaScript files, then no database is created.

- https://github.com/docker-library/docs/tree/db2ee79627f3baab969a0b2ed3d1081058cfd820/mongo#mongo_initdb_database

If you don't insert anything, then no database is created.

The user created by MONGO_INITDB_ROOT_USERNAME and MONGO_INITDB_ROOT_PASSWORD is in the admin database, so that is where authentication must be directed: like authSource or --authenticationDatabase