Hello, trying to create a database with the following configuration of my docker compose:
The docker compose file:
image: arm64v8/mongo
ports:
- 27017:27017
environment:
MONGO_INITDB_DATABASE: admin
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: password
volumes:
- ./mongo/database:/data/db
- ./mongo/init-mongo.js:/docker-entrypoint-initdb.d/init-mongo.js:ro
init-mongo.js:
db = db.getSiblingDB('admin');
db.auth("root", "password");
db = db.getSiblingDB('local')
db.createUser({
user: 'root',
pwd: 'password',
roles: [{role: 'readWrite', db: `local`}]
});
db.createCollection('schema', {capped: false});
When try to launch the docker compose, for any reason the logs said me:
MongoServerError: Cannot create users in the local database
That’s happens when I don’t have a database created, after that error message mongo create the database but no with the expected user and database, and I am not sure what I am doing bad, my version of Mongo its 6.0.5 and I using the arm64 image in a Apple Laptop with M1 Chipset, any advice will be appreciated, thank you