Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Docker Compose Generator with Traefik + Nginx

License: MIT Docker Traefik Nginx

🚀 Automated Docker Compose setup generator with modern reverse proxy configuration using Traefik and Nginx for production-ready microservices deployment.

✨ Features

  • 🔄 Interactive Setup: Easy command-line interface for service configuration
  • 🌐 Modern Reverse Proxy: Traefik v2.10 with automatic SSL/TLS via Let's Encrypt
  • 🔒 SSL Security: Built-in SSL/TLS termination with security headers
  • 📦 Multiple Services: Support for custom applications with domain routing
  • 🗄️ Database Support: MySQL, PostgreSQL, MongoDB options
  • ⚡ Cache & Queue: Redis and RabbitMQ integration
  • 📁 File Storage: MinIO S3-compatible storage
  • 🌍 Nginx Integration: Advanced nginx configurations per domain
  • 📊 Monitoring: Built-in Traefik dashboard
  • 🔧 Production Ready: Optimized configurations for production deployment

📋 Prerequisites

  • Docker Engine 20.10+
  • Docker Compose v2.0+
  • Domain names pointing to your server (for production SSL)
  • Basic understanding of Docker and networking

🚀 Quick Start

1. Clone Repository

git clone https://github.com/yourusername/docker-compose-generator.git
cd docker-compose-generator

2. Run Setup Script

chmod +x setup.sh
./setup.sh

3. Follow Interactive Prompts

The script will ask you to configure:

  • Network name and SSL email
  • Services (name, domain, port)
  • Database type (MySQL/PostgreSQL/MongoDB/None)
  • Optional services (Nginx, Redis, RabbitMQ, MinIO)

4. Start Services

./start-services.sh

Or manually:

docker-compose up -d

📁 Generated Structure

project/
├── 📄 .env                    # Environment variables
├── 📄 docker-compose.yml      # Main Docker Compose file
├── 📄 start-services.sh       # Startup script
├── 📁 data/                   # Persistent data volumes
│   ├── 📁 traefik/           # Traefik data & SSL certificates
│   ├── 📁 service1/          # Your custom services data
│   ├── 📁 mysql/             # Database data (if selected)
│   └── 📁 redis/             # Redis data (if selected)
├── 📁 config/                # Configuration files
│   ├── 📁 service1/          # Service configurations
│   └── 📁 mysql/             # Database configurations
├── 📁 logs/                  # Application logs
│   ├── 📁 traefik/           # Traefik logs
│   └── 📁 service1/          # Service logs
└── 📁 nginx/                 # Nginx configuration (if enabled)
    ├── 📄 nginx.conf         # Main nginx config
    ├── 📁 conf.d/            # Additional nginx configs
    ├── 📁 sites/             # Per-domain configurations
    ├── 📁 ssl/               # SSL certificates
    └── 📁 html/              # Static files

⚙️ Configuration Examples

Basic Web Application

# During setup:
Service name: frontend
Domain: app.example.com
Port: 3000

Service name: api
Domain: api.example.com  
Port: 8080

Complete Stack

# Services
frontend -> app.example.com:3000
api -> api.example.com:8080
admin -> admin.example.com:3001

# Database: MySQL
# Optional: Redis, Nginx enabled

🌐 Access URLs

After deployment, your services will be available at:

  • Traefik Dashboard: http://localhost:8080
  • Your Services: https://yourdomain.com
  • Database Admin (if enabled): https://db.yourdomain.com
  • File Storage (MinIO): https://storage.yourdomain.com

🔧 Nginx Configuration

Each service gets automatically configured nginx virtual host with:

  • HTTP to HTTPS redirect
  • SSL/TLS termination
  • Security headers
  • Rate limiting
  • Compression (gzip)
  • Static file caching
  • Health check endpoints

Sample Nginx Config

# HTTP redirect to HTTPS
server {
    listen 80;
    server_name api.example.com;
    return 301 https://$server_name$request_uri;
}

# HTTPS server
server {
    listen 443 ssl;
    server_name api.example.com;
    
    # SSL Configuration
    ssl_certificate /etc/nginx/ssl/live/api.example.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/ssl/live/api.example.com/privkey.pem;
    
    # Security & Performance optimizations
    # Rate limiting, compression, security headers...
    
    location / {
        proxy_pass http://api:8080;
        # Proxy headers for WebSocket support
    }
}

🔒 SSL/TLS Configuration

Production (Automatic)

  • Traefik automatically obtains SSL certificates via Let's Encrypt
  • Certificates are automatically renewed
  • HTTP traffic is redirected to HTTPS

Development (Self-Signed)

cd nginx/ssl
./generate-certs.sh

📊 Monitoring & Logs

View Service Status

docker-compose ps

View Logs

# All services
docker-compose logs -f

# Specific service
docker-compose logs -f traefik
docker-compose logs -f nginx
docker-compose logs -f your-service

Traefik Dashboard

Access real-time metrics and routing information at http://localhost:8080

🛠️ Customization

Adding Custom Services

  1. Edit docker-compose.yml:
your-service:
  image: your-image:latest
  container_name: your-service
  networks:
    - app-network
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.your-service.rule=Host(`your-domain.com`)"
    - "traefik.http.routers.your-service.tls.certresolver=letsresolver"
  1. Create nginx config (if using nginx):
cp nginx/sites/example.conf nginx/sites/your-domain.com.conf
# Edit the new file with your service details

Environment Variables

Edit .env file to customize:

# Global Settings
NETWORK_NAME=app-network
SSL_EMAIL=admin@example.com

# Service Configuration
API_DOMAIN=api.example.com
API_PORT=8080

# Database Credentials
MYSQL_ROOT_PASSWORD=secure_password
MYSQL_DATABASE=myapp

🔧 Troubleshooting

Common Issues

Services not accessible

# Check if services are running
docker-compose ps

# Check Traefik logs
docker-compose logs traefik

# Verify domain DNS resolution
nslookup yourdomain.com

SSL Certificate Issues

# Check Let's Encrypt rate limits
# Verify domain DNS points to your server
# Check Traefik logs for ACME errors
docker-compose logs traefik | grep acme

Port Conflicts

# Check what's using the ports
sudo netstat -tulpn | grep :80
sudo netstat -tulpn | grep :443

# Stop conflicting services
sudo systemctl stop apache2  # or nginx

Database Connection Issues

MySQL Connection

# Test connection from host
docker exec -it mysql mysql -u root -p

# Check if port is exposed
docker-compose ps mysql

🔄 Backup & Restore

Backup Data

# Create backup directory
mkdir -p backups/$(date +%Y%m%d)

# Backup data volumes
sudo tar -czf backups/$(date +%Y%m%d)/data.tar.gz data/
sudo tar -czf backups/$(date +%Y%m%d)/config.tar.gz config/

Restore Data

# Stop services
docker-compose down

# Restore data
sudo tar -xzf backups/20240101/data.tar.gz
sudo tar -xzf backups/20240101/config.tar.gz

# Start services
docker-compose up -d

🚀 Production Deployment

Server Requirements

  • RAM: 2GB minimum, 4GB recommended
  • Storage: 20GB minimum for Docker images and data
  • Network: Static IP address
  • DNS: Domain names configured with A records

Security Checklist

  • Change default passwords in .env
  • Configure firewall (UFW/iptables)
  • Setup regular backups
  • Enable Docker logging limits
  • Monitor resource usage
  • Regular security updates

Performance Optimization

# Docker logging limits
echo '{"log-driver":"json-file","log-opts":{"max-size":"10m","max-file":"3"}}' | sudo tee /etc/docker/daemon.json

# Restart Docker
sudo systemctl restart docker

📖 Documentation

Traefik

Nginx

Docker Compose

🤝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support


Star this repository if you find it helpful!

Made with ❤️ by BinaryDev

About

Generate ready-to-deploy multi-service Docker ssetup with Traefik, Let’s Encrypt, databases, and optional services like Redis, RabbitMQ, MinIO, and Nginx.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages