So, currently I have a docker-compose.yml
file that has the following:
version: "2"
services:
pastime:
build:
context: ./pastime
dockerfile: ./Dockerfile
volumes:
- ./pastime:/usr/src/app
- /usr/src/app/node_modules
ports:
- "3000:3000"
depends_on:
- mongo
environment:
- PORT=3000
- DATABASE_USER=pastime
- DATABASE_URL=mongo:27017
- DATABASE_PASS=pastime123
- DATABASE_NAME=pastime
command: npm run start:dev
mongo:
image: mongo:latest
restart: always
ports:
- "27017:27017"
environment:
- MONGO_INITDB_DATABASE=pastime
- MONGO_INITDB_ROOT_USERNAME=root
- MONGO_INITDB_ROOT_PASSWORD=root_password
volumes:
- ./init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
And also my init-mongo.js
file has:
db.createUser({
user: 'pastime',
pwd: 'pastime123',
roles: [
{
role: 'readWrite',
db: 'pastime'
}
]
})
I am not sure why, but the output I get everytime when I do a docker-compose logs -f mongo
comes up to:
SASL SCRAM-SHA-1 authentication failed for pastime on admin from client 172.19.0.3:55568 ; UserNotFound: Could not find user "pastime"...
I suspect that the init script is not running as I don't see kinds of logs about it in my mongo container.
Have followed a few examples, mainly following thru with this one: How to create a DB for MongoDB container on start up?