Skip to content
/ DbHub Public

A lightweight hub for running and managing multiple databases in Docker.

License

Notifications You must be signed in to change notification settings

YiWang24/DbHub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ—„οΈ Multi-Database Development Stack

A comprehensive Docker-based database management solution for development and testing environments. This project provides a unified way to manage MySQL, PostgreSQL, MongoDB, and Redis databases with their respective web management tools.

✨ Features

  • Multi-Database Support: MySQL 8.0, PostgreSQL 16, MongoDB 7, Redis 7
  • Web Management Tools: Adminer, pgAdmin, Mongo Express, Redis Insight
  • Auto-Initialization: Databases and sample data are created automatically
  • Automated Backups: Scheduled daily backups with configurable retention
  • Local Storage: All data stored in organized local directories
  • Professional Configuration: Optimized database configurations for development
  • Backup & Restore: Built-in backup scripts for all databases
  • Health Checks: Container health monitoring and dependencies
  • Network Isolation: Secure internal network for database communication

πŸš€ Quick Start

# Clone or navigate to the project directory
cd /path/to/database

# Copy environment template
cp .env.example .env

# Start all services
./db-manager.sh start

# Check status
./db-manager.sh status

πŸ“ Directory Structure

database/
β”œβ”€β”€ .env                    # Environment variables configuration
β”œβ”€β”€ .env.example           # Environment variables template
β”œβ”€β”€ docker-compose.yml     # Docker Compose configuration
β”œβ”€β”€ db-manager.sh          # Database management script
β”œβ”€β”€ README.md              # This documentation
β”œβ”€β”€ mysql/                 # MySQL related files
β”‚   β”œβ”€β”€ data/              # MySQL data storage
β”‚   β”œβ”€β”€ init/              # Initialization scripts
β”‚   β”œβ”€β”€ conf/              # Configuration files
β”‚   └── backup/            # Backup files
β”œβ”€β”€ postgres/              # PostgreSQL related files
β”‚   β”œβ”€β”€ data/              # PostgreSQL data storage
β”‚   β”œβ”€β”€ init/              # Initialization scripts
β”‚   └── backup/            # Backup files
β”œβ”€β”€ mongo/                 # MongoDB related files
β”‚   β”œβ”€β”€ data/              # MongoDB data storage
β”‚   β”œβ”€β”€ init/              # Initialization scripts
β”‚   └── backup/            # Backup files
β”œβ”€β”€ redis/                 # Redis related files
β”‚   β”œβ”€β”€ data/              # Redis data storage
β”‚   β”œβ”€β”€ conf/              # Configuration files
β”‚   └── backup/            # Backup files
β”œβ”€β”€ pgadmin/               # pgAdmin related files
β”‚   └── data/              # pgAdmin configuration storage
└── redisinsight/          # Redis Insight related files
    └── data/              # Redis Insight configuration storage

🎯 Use Cases

This database stack is perfect for:

  • Development Environment: Local development with multiple database types
  • Testing & QA: Consistent database setup across team members
  • Prototyping: Quick setup for new projects requiring various databases
  • Learning: Hands-on experience with different database technologies
  • CI/CD Pipeline: Standardized database environment for testing
  • Data Migration: Testing data migration scripts across different databases

πŸ”— Connection Information

MySQL

  • Host: localhost
  • Port: 13306
  • Root Password: Mysql!Root123
  • Character Set: utf8mb4

Dynamic Database Creation

The system supports automatic database and user creation based on the MYSQL_PROJECTS environment variable:

Configuration Format: database_name:username:password;

Single Project Example:

export MYSQL_PROJECTS="smart_sred:sred:123456;"

Multiple Projects Example:

export MYSQL_PROJECTS="smart_sred:sred:123456;blog:blogger:blog123;shop:shopper:shop456;"

Important Notes:

  • Each project definition ends with a semicolon (;)
  • Don't use colons (:) in passwords - use special characters like @#_ instead
  • Databases and users are created automatically when MySQL container starts
  • Each user gets full privileges on their corresponding database

Static Databases (always available):

  • test_db: User test_user, Password test123
  • dev_db: User dev_user, Password dev123

PostgreSQL

  • Host: localhost
  • Port: 15432
  • User: postgres
  • Password: PgPass!123

Databases:

  • postgres (default)
  • test_db
  • dev_db
  • analytics_db

MongoDB

  • Host: localhost
  • Port: 27017
  • Admin User: admin
  • Admin Password: MongoPass!123

Databases:

  • test_db: Users, products, orders and other test data
  • dev_db: Logs, sessions, cache and other development data

Redis

  • Host: localhost
  • Port: 16379
  • Password: RedisPass!123

Web Management Tools

Adminer (MySQL/PostgreSQL Management)

pgAdmin (PostgreSQL Management)

Mongo Express (MongoDB Management)

Redis Insight (Redis Management)

πŸ› οΈ Management Script Usage

The db-manager.sh script provides easy management of all database services:

# Start all services
./db-manager.sh start

# Check service status
./db-manager.sh status

# View logs
./db-manager.sh logs

# Enter database shell
./db-manager.sh shell mysql
./db-manager.sh shell postgres
./db-manager.sh shell mongo
./db-manager.sh shell redis

# Manual backup of all databases
./db-manager.sh backup

# Check backup status and recent backups
./db-manager.sh backup-status

# Stop services
./db-manager.sh stop

πŸ“¦ Automated Backup System

Backup Features

  • Scheduled Backups: Daily automated backups at 2 AM (configurable)
  • Retention Policy: Configurable retention period (default 7 days)
  • Compression: All backups are automatically compressed
  • Individual & Full: Both full cluster and individual database backups
  • Logging: Detailed backup logs with timestamps
  • Health Monitoring: Backup service status monitoring

Backup Configuration

# In .env file
BACKUP_CRON=0 2 * * *           # Daily at 2 AM
BACKUP_RETENTION_DAYS=7         # Keep for 7 days

Backup Locations

  • MySQL: mysql/backup/mysql_*_backup_*.sql.gz
  • PostgreSQL: postgres/backup/postgres_*_backup_*.sql.gz
  • MongoDB: mongo/backup/mongo_*_backup_*.tar.gz
  • Logs: */backup/backup_*.log

Manual Backup Commands

# Run immediate backup of all databases
./db-manager.sh backup

# Check backup service status and recent files
./db-manager.sh backup-status

# View backup logs
tail -f mysql/backup/backup_$(date +%Y-%m-%d).log
./db-manager.sh stop

Connection Examples

MySQL Command Line Connection:

mysql -h localhost -P 13306 -u sred -p smart_sred

PostgreSQL Command Line Connection:

psql -h localhost -p 15432 -U postgres -d test_db

MongoDB Command Line Connection:

mongosh "mongodb://admin:MongoPass!123@localhost:27017"

Redis Command Line Connection:

redis-cli -h localhost -p 16379 -a RedisPass!123

πŸ“ Application Connection Strings

Use these connection strings in your applications:

MySQL:

mysql://sred:123456@localhost:13306/smart_sred

PostgreSQL:

postgresql://postgres:PgPass!123@localhost:15432/test_db

MongoDB:

mongodb://admin:MongoPass!123@localhost:27017/test_db

Redis:

redis://:RedisPass!123@localhost:16379

πŸ”§ Configuration

Environment Variables

Copy .env.example to .env and customize the following settings:

  • ALLOWED_NET: Network access restriction (default: 192.168.2.%)
  • Database Ports: Custom port mappings for each database
  • Passwords: Strong passwords for all database services
  • Timezone: Database timezone settings

Database Initialization

Each database includes initialization scripts that create:

  • MySQL: smart_sred, test_db, and dev_db databases with users
  • PostgreSQL: Sample tables with UUID support and JSONB data
  • MongoDB: User, product, and order collections with indexes
  • Redis: Optimized configuration for development use

πŸ“Š Included Sample Data

The initialization scripts create sample data for testing:

  • Users: Admin and test user accounts
  • Products: Sample e-commerce product data
  • Orders: Test transaction records
  • Analytics: Event tracking examples

πŸ”’ Security Notes

  • Change default passwords in production
  • Restrict ALLOWED_NET to your specific network
  • Use strong passwords for all services
  • Consider enabling SSL/TLS for production use

🀝 Contributing

Feel free to submit issues, fork the repository, and create pull requests for any improvements.

πŸ“„ License

This project is open source and available under the MIT License.

About

A lightweight hub for running and managing multiple databases in Docker.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published