https://github.com/doguhannilt/mongodb-docker-starter
Mongodb Docker Starter
https://github.com/doguhannilt/mongodb-docker-starter
mongodb shell
Last synced: 2 months ago
JSON representation
Mongodb Docker Starter
- Host: GitHub
- URL: https://github.com/doguhannilt/mongodb-docker-starter
- Owner: Doguhannilt
- Created: 2025-04-04T22:51:13.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-04T22:55:15.000Z (about 1 year ago)
- Last Synced: 2025-04-04T23:27:11.010Z (about 1 year ago)
- Topics: mongodb, shell
- Language: Shell
- Homepage:
- Size: 0 Bytes
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Quick Start
### 1. Start the MongoDB Container
```bash
./scripts/start-db.sh
```
This will:
- Create a Docker volume (if not exists)
- Create a Docker network (if not exists)
- Start a MongoDB container with custom credentials
- Mount an init script to configure your database and user
---
### 2. Stop & Clean Up the Environment
```bash
./scripts/cleanup.sh
```
This will:
- Remove the MongoDB container (if running)
- Remove the Docker volume
- Remove the Docker network
---
## โ๏ธ Environment Configuration
The scripts rely on the following environment files:
| File | Description |
|------------------|---------------------------------|
| `.env.db` | Database container name |
| `.env.network` | Custom Docker network name |
| `.env.volume` | Docker volume name |
> Example `.env.db`:
```env
DB_CONTAINER_NAME=mongodb
```
---
## ๐งฉ Initialization Script
The following file is mounted on container startup:
```bash
db-config/mongo-init.js
```
It creates the application-specific database and user with custom roles.
> Example content:
```js
const key_value_db = process.env.KEY_VALUE_DB;
const keyValueUser = process.env.KEY_VALUE_USER;
const keyValuePassword = process.env.KEY_VALUE_PASSWORD;
db = db.getSiblingDB(key_value_db);
db.createUser({
user: keyValueUser,
pwd: keyValuePassword,
roles: [{ role: 'readWrite', db: key_value_db }]
});
```
---
## ๐ Project Structure
```bash
.
โโโ db-config/
โ โโโ mongo-init.js
โโโ scripts/
โ โโโ start-db.sh
โ โโโ cleanup.sh
โโโ .env.db
โโโ .env.network
โโโ .env.volume
โโโ README.md
```
---
## ๐งผ Notes
- The MongoDB image used: `mongodb/mongodb-community-server:7.0-ubuntu2204`
- Container is run with `--rm` so it's ephemeral. Data persists via Docker volume.
- Ensure Docker is running before executing the scripts.