I have a docker-compose.yml file with below config.
version: '0.01'
services:
mongodb:
image: mongodb/mongodb-community-server:latest
container_name: test-mongodb
restart: always
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: testadmin
MONGO_INITDB_ROOT_PASSWORD: testadmin
MONGO_INITDB_DATABASE: "peopledb"
volumes:
- ./setup/mongo-init-scripts:/docker-entrypoint-initdb.d
and the init-db.js as below
db.createUser({
user: "admin",
pwd: "admin_password",
roles: [
{
role: "readWrite",
db: "peopledb"
}
]
});
db.people.insertMany([
{ name: "first 1", value: 10 },
{ name: "second 2", value: 20 },
// Add more default documents as needed
]);
Everything works fine without a hitch, except the people collection is created in “Test” db instead of “peopledb” in the docker-compose and init-js.
What am I missing…
TIA