I am trying to connect correctly to the mongo instance run by docker. I have the following config.yml
version: "3"
services:
mongo-server:
container_name: mongo-server
image: mongo:4.4.2
restart: always
ports:
- "27017:27017"
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_ROOT_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_ROOT_PASSWORD}
volumes:
- mongo-data:/data/db
app:
container_name: app
image: "node:12"
working_dir: /home/node/app
environment:
- NODE_ENV=production
volumes:
- ./:/home/node/app
ports:
- "8888:8888"
command: "npm run start"
depends_on:
- mongo-server
mongo-express:
container_name: mongo-admin
image: mongo-express:0.54
restart: always
ports:
- "8081:8081"
environment:
- ME_CONFIG_MONGODB_SERVER=mongo-server
- ME_CONFIG_MONGODB_PORT=27017
- ME_CONFIG_MONGODB_ENABLE_ADMIN=true
- ME_CONFIG_MONGODB_ADMINUSERNAME=${MONGO_ROOT_USER}
- ME_CONFIG_MONGODB_ADMINPASSWORD=${MONGO_ROOT_PASSWORD}
- ME_CONFIG_BASICAUTH_USERNAME=${MONGO_EXPRESS_LOGIN}
- ME_CONFIG_BASICAUTH_PASSWORD=${MONGO_EXPRESS_PASSWORD}
depends_on:
- mongo-server
volumes:
mongo-data:
I have checked that the .env vars are being passed correctly with docker-compose config
From there I spin up the docker images by running:
docker-compose up -d
I found out how to delete the volumes which was the first major issue. Now connecting to the database in my app is next. The supplied username and password aren't quite working.
The app is attempting to connect to the following string with mongoose connect:
`mongodb://${process.env.MONGO_ROOT_USER}:${process.env.MONGO_ROOT_PASSWORD}@mongo:27017/app`
But that isn't working and I am not quite sure why. If anyone has an idea of what it should be please let me know