It took me some time to get that I coulnd’t use ME_CONFIG_MONGODB_URL to connect to my Mongo database so I thought I make a post so I’ll remember until next time.
First, let’s see how it is done in docker compose (docker-compose.yml).
version: '3.8'
services:
mongo:
image: mongo
restart: always
ports:
- '27017:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
environment:
ME_CONFIG_MONGODB_ADMINUSERNAME: root
ME_CONFIG_MONGODB_ADMINPASSWORD: example
ME_CONFIG_MONGODB_SERVER: mongo
ME_CONFIG_BASICAUTH_USERNAME: root
ME_CONFIG_BASICAUTH_PASSWORD: example
That’s all, then when we run compose up we will create these containers and can go to http://localhost:8081/ to administrate our mongodb which is running the default port 27017 on localhost.