mongo-express-docker
mongo-express-docker copied to clipboard
Authentication failed.
Waiting for 192.168.150.31:27017...
,Welcome to mongo-express
,------------------------
,
,
,Mongo Express server listening at http://0.0.0.0:8081
,Server is open to allow connections from anyone (0.0.0.0)
,Database connected
,{ MongoError: Authentication failed.
, at Function.MongoError.create (/node_modules/mongodb-core/lib/error.js:31:11)
, at /node_modules/mongodb-core/lib/connection/pool.js:483:72
, at authenticateStragglers (/node_modules/mongodb-core/lib/connection/pool.js:429:16)
, at Connection.messageHandler (/node_modules/mongodb-core/lib/connection/pool.js:463:5)
, at Socket.
Apparently this problem in unsolvable :(. Several threads were open and no replies to them.
waiting for this solve still as well
Have you tried solution https://github.com/mongo-express/mongo-express-docker/issues/35#issuecomment-543788773 as-is ?
Provided soultions work without problem for me on ubuntu and macos.
But according to this https://github.com/docker-library/mongo/issues/451 it may depend on distro and versions indeed. So you should check this at least.
I ran into this today while using the following docker-compose.yml
:
version: "3.9"
services:
db:
image: mongo:latest
ports:
- 27017:27017
volumes:
- ./data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
environment:
MONGO_INITDB_ROOT_USERNAME: dev
MONGO_INITDB_ROOT_PASSWORD: example
web:
image: mongo-express:latest
ports:
- 8081:8081
depends_on:
- db
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: dev
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_SERVER: db
The only way to fix it I've found has been to restart the mongo-express container after the mongo one has been already been initialized. It seems that the mongo container is reported ready before it actually is, making mongo-express try to connect to a service that is not yet available. If you restart the mongo-express container it seems to connect just fine.
After a couple of hours of trying different combinations and reading multiple threads, I got my setup to work using the following docker-compose.yml
, I hope it helps anyone stuck with this issue
version: '3.9'
services:
mongodb:
container_name: mongo-dev
image: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME:"${MONGO_ROOT_USER}"
- MONGO_INITDB_ROOT_PASSWORD:"${MONGO_ROOT_PASSWORD}"
- MONGO_INITDB_DATABASE:"db"
ports:
- '27017:27017'
mongo-express:
container_name: mongo-express
image: mongo-express:0.54.0
restart: always
depends_on:
- mongodb
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME="${MONGO_ROOT_USER}"
- ME_CONFIG_MONGODB_ADMINPASSWORD="${MONGO_ROOT_PASSWORD}"
- ME_CONFIG_MONGODB_SERVER=mongo-dev
- ME_CONFIG_BASICAUTH_USERNAME=${MONGOEXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGOEXPRESS_PASSWORD}
ports:
- '8081:8081'
#35 I hope my reply to this issue helps you a lot!
@Asher-Ding thanks.
@wade-liwei please can you check?