Couldn't access mongo-express from Docker

899 Views Asked by At

I am trying to carry out some experiments with Docker, MongoDB, and mongo-express.

Here was what I did:

docker network create my-network 
docker run -d -p 27017:27017 --network my-network --name my-mongo -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=pass mongo 
docker run -d -p 8081:8081   --network my-network --name my-mongo-express -e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" -e ME_CONFIG_MONGODB_SERVER="my-mongo" -e ME_CONFIG_BASICAUTH_USERNAME="admin" -e ME_CONFIG_BASICAUTH_PASSWORD="pass" mongo-express

No error message was received apparently.

However, when I entered the address "localhost:8081" on Chrome, the page displayed an error message saying:

This page isn’t working
localhost didn’t send any data.
ERR_EMPTY_RESPONSE

How can I fix this?

1

There are 1 best solutions below

0
Hans Kilian On BEST ANSWER

You set the admin username and password on the database, but then you use the 'normal' user environment variables to try to log on. Instead of ME_CONFIG_BASICAUTH_USERNAME and ME_CONFIG_BASICAUTH_PASSWORD, you should use ME_CONFIG_MONGODB_ADMINUSERNAME and ME_CONFIG_MONGODB_ADMINPASSWORD, like this

docker run -d -p 8081:8081   --network my-network --name my-mongo-express -e ME_CONFIG_OPTIONS_EDITORTHEME="ambiance" -e ME_CONFIG_MONGODB_SERVER="my-mongo" -e ME_CONFIG_MONGODB_ADMINUSERNAME="admin" -e ME_CONFIG_MONGODB_ADMINPASSWORD="pass" mongo-express