I'm trying to get docker-compose to connect to mongodb using Authentication. In the past I've used a URI string containing the username and password, however, when I run docker up
it returns MongoError: Authentication failed.
Using terminal I can get into the docker container and manually access mongo using the credentials in the uri string, which means the database is running. I'm new to docker. Can someone explain why my URI string doesn't work and how I should fix it.
version: "3.8"
services:
product-service:
build:
context: "."
dockerfile: "./product-service/Dockerfile"
container_name: product-service
depends_on:
- product-service-db
ports:
- "7300:7300"
volumes:
- ./product-service:/opt/app
links:
- product-service-db
environment:
- DB_URI=mongodb://root:example@product-service-db:27017/Products
product-service-db:
image: mongo:4.4.2
restart: always
ports:
- "7399:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example