docker-library / docker-library/mongo
Add an example to documentation for "Initializing a fresh instance"
Nobody has claimed this yet.
- Dominant language
- Shell
- Stars
- 1.1k
- Forks
- 658
- Avg merge
- 4h 40m
- Merged PRs (30d)
- 1
Description
Problem
Setting up a user and db (other than the admin user and test db) is a little opaque.
This link How to create a DB for MongoDB container on start up? with over 268K views shows how much of an issue the lack of documentation is. There are many other variations of the search term above, so I'd imagine the numbers would be a lot higher if they were all tallied.
Proposal
Please include something like the below in that section of the documentation
docker-compose.yaml
version: '3.8'
services:
mongodb:
image: mongo:latest
container_name: mongodb
restart: always
environment:
MONGO_INITDB_ROOT_USERNAME: <admin user>
MONGO_INITDB_ROOT_PASSWORD: <admin password>
MONGO_INITDB_DATABASE: <custom db>
ports:
- 27017:27017
volumes:
- ./mongo-init.js:/docker-entrypoint-initdb.d/mongo-init.js:ro
mongo-init.js
print('Init Script - Started Adding the User Roles.');
// use the admin db to create a new user and give that new user permission to the db
// mongo seems to lazy load the db, meaning it'll create the db when a collection is first added
// but the newly created user will still have access to the db
db = db.getSiblingDB('admin');
db.createUser({
user: '<custom user>',
pwd: '<custom user password>',
roles: [{ role: 'readWrite', db: '<custom db>' }],
});
print('Init Script - Ended Adding the User Roles.');
please include the shell version
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the documentation section titled “Initializing a fresh instance” and review the proposed docker-compose.yaml and mongo-init.js examples. Verify the MongoDB initialization flow, then add the requested shell version and examples for creating a custom user and database. Done means the documentation clearly covers this setup and the examples are usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, docker-compose, javascript, mongodb, shell
- Domain
- databases, devops, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100