Skip to content

Commit

Permalink
feat: add mongodb
Browse files Browse the repository at this point in the history
  • Loading branch information
lwshen committed Nov 7, 2024
1 parent 5b4464c commit fe0b080
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mongodb/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
MONGO_VERSION=8
MONGO_PORT=27017
MONGO_UI_PORT=4321
MONGO_INITDB_ROOT_USERNAME=root
MONGO_INITDB_ROOT_PASSWORD=zaq12wsx
49 changes: 49 additions & 0 deletions mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# MongoDB

This repository contains two Docker Compose configurations for running MongoDB with a web-based UI:
- A basic setup without authentication
- A secure setup with username/password authentication

## Environment Variables

Create a `.env` file in the same directory with the following variables:

```env
MONGO_VERSION=6.0
# Required only for password-protected setup
MONGO_INITDB_ROOT_USERNAME=admin
MONGO_INITDB_ROOT_PASSWORD=your_secure_password
```

## Basic Setup (No Authentication)

To start MongoDB without authentication:

```bash
docker compose -f docker-compose.yml up -d
```

## Secure Setup (With Authentication)

To start MongoDB with password protection:

```bash
docker compose -f docker-compose-with-password.yml up -d
```

## Accessing the Services

- **MongoDB**: Available at `localhost:27017` for default
- **MongoDB UI**: Access through your web browser at `http://localhost:4321` for default

## Stopping the Services

To stop and remove the containers:

```bash
# For basic setup
docker compose -f docker-compose.yml down

# For password-protected setup
docker compose -f docker-compose-with-password.yml down
```
33 changes: 33 additions & 0 deletions mongodb/docker-compose-with-password.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
version: "3.4"

services:
mongo:
image: mongo:${MONGO_VERSION}
container_name: mongo
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
ports:
- ${MONGO_PORT}:27017
cpus: 0.5
mem_limit: 256M
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 15s
timeout: 10s
retries: 5
start_period: 40s

mongo-ui:
container_name: mongo-ui
image: ugleiton/mongo-gui
depends_on:
mongo:
condition: service_healthy
restart: always
ports:
- ${MONGO_UI_PORT}:4321
environment:
- MONGO_URL=mongodb://${MONGO_INITDB_ROOT_USERNAME}:${MONGO_INITDB_ROOT_PASSWORD}@mongo:27017
cpus: 0.25
mem_limit: 256M
30 changes: 30 additions & 0 deletions mongodb/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
version: "3.4"

services:
mongo:
image: mongo:${MONGO_VERSION}
container_name: mongo
ports:
- ${MONGO_PORT}:27017
cpus: 0.5
mem_limit: 256M
healthcheck:
test: echo 'db.runCommand("ping").ok' | mongosh localhost:27017/test --quiet
interval: 15s
timeout: 10s
retries: 5
start_period: 40s

mongo-ui:
container_name: mongo-ui
image: ugleiton/mongo-gui
depends_on:
mongo:
condition: service_healthy
restart: always
ports:
- ${MONGO_UI_PORT}:4321
environment:
- MONGO_URL=mongodb://mongo:27017
cpus: 0.25
mem_limit: 256M

0 comments on commit fe0b080

Please sign in to comment.