I'm currently creating a database and a python file that controls it. The issue i'm having is that it runs but the creation of the user seems to not be happening post the docker-compose up command. My knowledge on users in Mongo is limited but realistically I only need one user for now with most of the rights. My docker-compose file looks like this:
version: '3'
services:
storing_script:
build:
context: .
dockerfile: Dockerfile
depends_on:
- mongo
mongo:
image: mongo:latest
environment:
MONGO_INITDB_ROOT_USERNAME: user
MONGO_INITDB_ROOT_PASSWORD: pas342%4@!
MONGO_INITDB_DATABASE: motionDB
volumes:
- ${PWD}/mongo-data:/data/db
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
command: mongod --port 27018
restart: unless-stopped
The storing script has its own DockerFile. I've connected to the mongo container and it does run, it does work but it seems to completely ignore the creation of a user. I specified in the volumes to use the js file for the creation which looks like:
db.createUser(
{
user: "<user for database which shall be created>",
pwd: "<password of user>",
roles: [
{
role: "readWrite",
db: "<database to create>"
}
]
}
);
Is my compose file the issue, or do I need to manually create and authenticate a user? I looked at other topics and they all seem to recommend this. A specific topic said when running docker-compose up I should receive a "user created" (https://stackoverflow.com/a/42973849/15718345) which i never receive. Again i'm not a Mongo expert, my goal is just to get a user working as soon as possible.