1

I'm currently trying to deploy my mongoDB and mongo-express containers locally with docker-compose. Right now my settings are just like default settings:

  mongo:
    image: mongo:latest
    restart: on-failure
    container_name: mongo
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: PassW0rd
    ports:
      - 27017:27017
    volumes:
      - ./docker/nosql/mongo/data:/data/db
      - ./docker/nosql/mongo/dbconfig:/data/configdb
  mongo-express:
    image: mongo-express
    restart: always
    ports:
      - 8888:8081
    container_name: mongo-express
    environment:
      ME_CONFIG_MONGODB_SERVER: mongo
      ME_CONFIG_MONGODB_ENABLE_ADMIN: true
      ME_CONFIG_MONGODB_ADMINUSERNAME: root
      ME_CONFIG_MONGODB_ADMINPASSWORD: PassW0rd
      ME_CONFIG_MONGODB_URL: mongodb://root:PassW0rd@mongo:27017/
    depends_on:
      - mongo

However mongo-express container cannot connect to mongo because of authentication failed:

Inside mongo-express container log

(node:7) UnhandledPromiseRejectionWarning: MongoNetworkError: failed to connect to server [mongo:27017] on first connect [Error: connect ECONNREFUSED 172.24.0.3:27017
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
  name: 'MongoNetworkError'
}]
    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 /node_modules/mongodb/lib/core/connection/connect.js:32:7
    at callback (/node_modules/mongodb/lib/core/connection/connect.js:300:5)
    at Socket.<anonymous> (/node_modules/mongodb/lib/core/connection/connect.js:330:7)
    at Object.onceWrapper (events.js:421:26)
    at Socket.emit (events.js:314:20)
    at emitErrorNT (internal/streams/destroy.js:92:8)
    at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)

I also try looking at the log inside Mongo container, and it seems like the user root does not exist inside the database admin?

Inside mongo container log:

{"t":{"$date":"2023-07-10T03:13:53.367+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn10","msg":"client metadata","attr":{"remote":"172.24.0.4:50012","client":"conn10","doc":{"driver":{"name":"nodejs","version":"3.7.3"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.15.90.1-microsoft-standard-WSL2"},"platform":"'Node.js v12.22.7, LE (legacy)"}}}
{"t":{"$date":"2023-07-10T03:13:53.368+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn10","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":{"user":"root","db":"admin"}}}
{"t":{"$date":"2023-07-10T03:13:53.368+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn10","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"root","authenticationDatabase":"admin","remote":"172.24.0.4:50012","extraInfo":{},"error":"UserNotFound: Could not find user \"root\" for db \"admin\""}}
{"t":{"$date":"2023-07-10T03:13:53.373+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn10","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"root","authenticationDatabase":"admin","remote":"172.24.0.4:50012","extraInfo":{},"error":"UserNotFound: Could not find user \"root\" for db \"admin\""}}
{"t":{"$date":"2023-07-10T03:13:53.384+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn10","msg":"Connection ended","attr":{"remote":"172.24.0.4:50012","uuid":"8ff45e65-fb8f-4451-843d-d4c682d48812","connectionId":10,"connectionCount":0}}
{"t":{"$date":"2023-07-10T03:14:00.863+00:00"},"s":"I",  "c":"NETWORK",  "id":22943,   "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.24.0.4:39566","uuid":"1ff92968-4345-471b-a9e2-789fb9508e01","connectionId":11,"connectionCount":1}}
{"t":{"$date":"2023-07-10T03:14:00.878+00:00"},"s":"I",  "c":"NETWORK",  "id":51800,   "ctx":"conn11","msg":"client metadata","attr":{"remote":"172.24.0.4:39566","client":"conn11","doc":{"driver":{"name":"nodejs","version":"3.7.3"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"5.15.90.1-microsoft-standard-WSL2"},"platform":"'Node.js v12.22.7, LE (legacy)"}}}
{"t":{"$date":"2023-07-10T03:14:00.879+00:00"},"s":"I",  "c":"ACCESS",   "id":20251,   "ctx":"conn11","msg":"Supported SASL mechanisms requested for unknown user","attr":{"user":{"user":"root","db":"admin"}}}
{"t":{"$date":"2023-07-10T03:14:00.880+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn11","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"root","authenticationDatabase":"admin","remote":"172.24.0.4:39566","extraInfo":{},"error":"UserNotFound: Could not find user \"root\" for db \"admin\""}}
{"t":{"$date":"2023-07-10T03:14:00.885+00:00"},"s":"I",  "c":"ACCESS",   "id":20249,   "ctx":"conn11","msg":"Authentication failed","attr":{"mechanism":"SCRAM-SHA-1","speculative":false,"principalName":"root","authenticationDatabase":"admin","remote":"172.24.0.4:39566","extraInfo":{},"error":"UserNotFound: Could not find user \"root\" for db \"admin\""}}
{"t":{"$date":"2023-07-10T03:14:00.902+00:00"},"s":"I",  "c":"NETWORK",  "id":22944,   "ctx":"conn11","msg":"Connection ended","attr":{"remote":"172.24.0.4:39566","uuid":"1ff92968-4345-471b-a9e2-789fb9508e01","connectionId":11,"connectionCount":0}}

0 Answers0