https://github.com/yingding/docker-mongodb
configure MongoDB docker container using the official MongoDB docker image
https://github.com/yingding/docker-mongodb
Last synced: 2 months ago
JSON representation
configure MongoDB docker container using the official MongoDB docker image
- Host: GitHub
- URL: https://github.com/yingding/docker-mongodb
- Owner: yingding
- License: mit
- Created: 2020-11-20T16:59:34.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2020-12-01T11:03:43.000Z (over 5 years ago)
- Last Synced: 2025-02-23T23:43:25.252Z (over 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# docker-mongodb
configure a docker container of MongoDB using an official docker image of MongoDB, which also automatically activates authorization security settings and add a root user.
### Copy .env file
* `cd db && cp .env-template .env` to copy the template
* `vi .env` to set the root user and password, also the path variable `${MY_VOLUMES_PWD}` to existing mongodb files
* This settings will create a user `root` in system db `admin with roles `{role: "root", db: "admin"}
### Copy init-mongo.js file
* `cd db && cp init-mongo-template.js init-mongo.js`
* `vi init-mongo.js` to edit the user name or password to add a user.
### Run install
`cd db && sh start_container.sh`
### Notice
* Should there is already mongodb admin database in the binded system volume, the root user will not be triggered and init-mongo.js will not be called.
* you can rename the init-mongo.js to anything you like as long as it is still a javascript file.
### Additional reference:
* docker-compose volume docs: https://docs.docker.com/compose/compose-file/#volumes
* create a docker-compose.yml file for mongodb https://stackoverflow.com/questions/34559557/how-to-enable-authentication-on-mongodb-through-docker/42973849#42973849
* Adding additional users during the container creation: https://medium.com/faun/managing-mongodb-on-docker-with-docker-compose-26bf8a0bbae3
* Following https://stackoverflow.com/questions/20117104/mongodb-root-user/40925394#40925394 to edit init-mongo.js
# MongoDB
some useful commands and knowledge regarding MongoDB is available in a [Tech Doc](techdoc.md).