zenkiet/traefik-tunnel-expose

By zenkiet

โ€ขUpdated 4 months ago

Exposing internal services securely via Traefik Proxy & Cloudflare Tunnel

Image
Networking
Web servers
Web analytics
1

2.8K

zenkiet/traefik-tunnel-expose repository overview

โ ๐Ÿš€ Traefik Tunnel Expose

Icon

Docker Image Docker Pulls Docker Image Version GitHub Workflow Status License GitHub stars

๐ŸŒ A powerful Docker solution combining Traefik reverse proxy with Cloudflare Tunnel Expose your local services to the internet securely with automatic SSL and DNS management

๐Ÿณ Docker Hubโ  โ€ข ๐Ÿ“– Documentationโ  โ€ข ๐Ÿš€ Quick Startโ  โ€ข ๐Ÿ’ฌ Discussionsโ 


โ ๐Ÿ“‹ Table of Contents


โ โœจ Features

โ โšก Core Features
  • ๐Ÿ”„ Traefik v3 - Modern reverse proxy with service discovery
  • โ˜๏ธ Cloudflare Tunnel - Secure tunneling without port forwarding
  • ๐Ÿ”’ Auto SSL - Let's Encrypt certificates with DNS challenge
  • ๐Ÿค– DNS Management - Automatic subdomain creation
  • ๐Ÿ“Š Real-time Dashboard - Monitor services and metrics
  • ๐Ÿ”ง Hot Reload - Zero-downtime configuration updates
โ ๐Ÿ›ก๏ธ Security & Performance
  • ๐Ÿ” End-to-end Encryption - Secure tunnel connection
  • ๐Ÿšซ No Port Opening - Firewall-friendly architecture
  • โšก Load Balancing - Distribute traffic efficiently
  • ๐ŸŽฏ Middleware Support - Rate limiting, headers, auth
  • ๐Ÿ“ Comprehensive Logging - Access and error logs
  • ๐Ÿณ Lightweight - Alpine Linux based container

โ ๐Ÿ—๏ธ Architecture

graph TB
    A[๐ŸŒ Internet] --> B[โ˜๏ธ Cloudflare CDN]
    B --> C[๐Ÿ”’ Cloudflare Tunnel]
    C --> D[๐Ÿš€ Traefik Proxy]
    D --> E[๐Ÿ“ฑ Your Services]

    F[๐Ÿค– DNS API] --> G[๐Ÿ“ Auto DNS Records]
    H[๐Ÿ” Let's Encrypt] --> I[๐Ÿ“œ SSL Certificates]

Flow Overview:

  1. ๐ŸŒ Internet Traffic โ†’ Cloudflare CDN for caching and protection
  2. ๐Ÿ”’ Secure Tunnel โ†’ Encrypted connection through Cloudflare Tunnel
  3. ๐Ÿš€ Traefik Proxy โ†’ Intelligent routing to your services
  4. ๐Ÿค– Automatic SSL โ†’ Let's Encrypt certificates via DNS challenge
  5. ๐Ÿ“ DNS Management โ†’ Auto-create subdomains for services

โ ๐Ÿš€ Quick Start

โ ๐Ÿ“ฆ Prerequisites
  • ๐Ÿณ Docker & Docker Compose
  • โ˜๏ธ Cloudflare account with domain
  • ๐Ÿ”‘ Cloudflare API tokens
โ 1๏ธโƒฃ Clone Repository
git clone https://github.com/zenkiet/traefik-tunnel-expose.git
cd traefik-tunnel-expose
โ 2๏ธโƒฃ Environment Setup
# Copy example environment file
cp env.example .env

# Edit configuration
nano .env  # or your preferred editor
โ ๐Ÿ”ง Required Environment Variables
# ===== REQUIRED =====
# Cloudflare Configuration
CF_API_TOKEN=your_cloudflare_api_token_here
CF_ZONE_ID=your_cloudflare_zone_id_here
CF_TUNNEL_ID=your_cloudflare_tunnel_id_here
CF_ACCOUNT_ID=your_cloudflare_account_id
[email protected]

# Domain Configuration
BASE_DOMAIN=yourdomain.com
HOST=127.0.0.1

# SSL Configuration (use staging for testing)
ACME_CA_SERVER=https://acme-staging-v02.api.letsencrypt.org/directory
โ 3๏ธโƒฃ Deploy services
# ๐Ÿš€ Start services
make dev # or make prod (for production)

# ๐Ÿ“Š Check status
make status

# ๐Ÿ“ View logs
make logs
โ 4๏ธโƒฃ Access Dashboard

โ โš™๏ธ Service Configuration

โ ๐Ÿ“ Adding New Services

Create configuration files in conf.d/ directory:

โ ๐Ÿ“„ Example: conf.d/myapp.yml
# ๐Ÿš€ HTTP Router and Service Configuration
http:
  routers:
    myapp:
      rule: "Host(`myapp.yourdomain.com`)"
      service: "myapp-service"
      entrypoints:
        - websecure
      tls:
        certResolver: cloudflare
      middlewares:
        - default-headers
        - rate-limit

  services:
    myapp-service:
      loadBalancer:
        servers:
          - url: "http://myapp-container:3000"
        healthCheck:
          path: "/health"
          interval: "30s"

  middlewares:
    default-headers:
      headers:
        frameDeny: true
        sslRedirect: true
        browserXssFilter: true
        contentTypeNosniff: true
        forceSTSHeader: true
        stsIncludeSubdomains: true
        stsPreload: true
        stsSeconds: 31536000

    rate-limit:
      rateLimit:
        burst: 100
        average: 50
โ ๐Ÿ”ง Advanced Service Configuration
๐Ÿ“ฑ Web Application with Authentication
http:
  routers:
    webapp-secure:
      rule: "Host(`webapp.yourdomain.com`)"
      service: "webapp"
      entrypoints:
        - websecure
      tls:
        certResolver: cloudflare
      middlewares:
        - auth
        - secure-headers

  services:
    webapp:
      loadBalancer:
        servers:
          - url: "http://webapp:8080"

  middlewares:
    auth:
      basicAuth:
        users:
          - "admin:$2y$12$..."  # Generated with htpasswd

    secure-headers:
      headers:
        accessControlAllowMethods:
          - GET
          - OPTIONS
          - PUT
        accessControlAllowOriginList:
          - https://yourdomain.com
        accessControlMaxAge: 100
        hostsProxyHeaders:
          - "X-Forwarded-Host"
๐Ÿ—„๏ธ Database Service (Internal Only)
http:
  routers:
    db-admin:
      rule: "Host(`db.yourdomain.com`)"
      service: "database-admin"
      entrypoints:
        - websecure
      tls:
        certResolver: cloudflare
      middlewares:
        - ip-whitelist
        - auth

  services:
    database-admin:
      loadBalancer:
        servers:
          - url: "http://adminer:8080"

  middlewares:
    ip-whitelist:
      ipWhiteList:
        sourceRange:
          - "192.168.1.0/24"
          - "10.0.0.0/8"

โ ๐Ÿ” Cloudflare Setup

โ 1๏ธโƒฃ API Token Creation
  1. ๐ŸŒ Navigate to Cloudflare API Tokensโ 
  2. ๐Ÿ”ง Create Custom Token with permissions:
ScopeResourcePermission
ZoneZone:ReadSpecific zones
ZoneDNS:EditSpecific zones
AccountCloudflare Tunnel:EditSpecific accounts
  1. ๐Ÿ“‹ Copy the generated token
โ 2๏ธโƒฃ Cloudflare Tunnel Setup
# ๐Ÿ“ฅ Install cloudflared
curl -L https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb -o cloudflared.deb
sudo dpkg -i cloudflared.deb

# ๐Ÿ” Authenticate with Cloudflare
cloudflared tunnel login

# ๐Ÿš‡ Create tunnel
cloudflared tunnel create my-tunnel

# ๐ŸŽซ Generate tunnel token
cloudflared tunnel token my-tunnel
โ ๐ŸŒ Method 2: Using Cloudflare Dashboard
  1. Go to Zero Trust โ†’ Networks โ†’ Tunnels
  2. Create new tunnel
  3. Install connector and copy the token
โ 3๏ธโƒฃ Generate credentials file
cloudflared tunnel token --cred-file ./credentials.json <TUNNEL_ID>
โ 4๏ธโƒฃ DNS Configuration

The service automatically creates DNS records, but you can manually verify:

# ๐Ÿ” Check DNS records
dig myapp.yourdomain.com
nslookup myapp.yourdomain.com

โ ๐Ÿ“Š Management Commands

โ ๐Ÿš€ Service Management
# Start services
make run                    # Start with auto-restart
make dev                    # Development mode
make prod                   # Production mode

# Control services
make stop                   # Stop all services
make restart                # Zero-downtime restart
make update                 # Update to latest images
โ ๐Ÿ“Š Monitoring & Diagnostics
# View service status
make status                 # Comprehensive status overview
make health-check          # Full health diagnostics

# Log management
make logs                  # Live logs with timestamps
make logs-traefik          # Traefik-specific logs
make logs-errors           # Error logs only
โ ๐Ÿ”ง Development & Testing
# Quality assurance
make test                  # Run test suite
make lint                  # Validate configurations
make security-scan         # Security vulnerability scan

# Development tools
make shell                 # Enter container shell
make info                  # Image information
โ ๐Ÿงน Maintenance
# Cleanup operations
make clean                 # Clean containers & resources
make clean-all             # Deep cleanup with cache
make clean-logs            # Remove old log files
โ ๐Ÿ”„ CI/CD Pipeline
# Build and deployment
make build                 # Build Docker image
make push                  # Push to registry
make release VERSION=v1.0.0  # Create versioned release

# Pipeline execution
make ci                    # Complete CI pipeline
make cd                    # Complete CD pipeline
โ ๐Ÿš€ Service Management
# Start services
make run                    # Start with auto-restart
make dev                    # Development mode
make prod                   # Production mode

# Control services
make stop                   # Stop all services
make restart                # Zero-downtime restart
make update                 # Update to latest images

โ ๐Ÿ”ง Advanced Configuration

โ ๐ŸŽ›๏ธ Custom Traefik Configuration

Create config/traefik-dynamic.yml for advanced settings:

# ๐Ÿ” TLS Configuration
tls:
  options:
    default:
      sslProtocols:
        - "TLSv1.2"
        - "TLSv1.3"
      cipherSuites:
        - "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384"
        - "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305"
        - "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256"

# ๐Ÿ“Š Global Middlewares
http:
  middlewares:
    secure-headers:
      headers:
        accessControlAllowMethods:
          - GET
          - OPTIONS
          - PUT
        accessControlMaxAge: 100
        hostsProxyHeaders:
          - "X-Forwarded-Host"
        referrerPolicy: "same-origin"
โ ๐Ÿš€ Performance Optimization
โšก Performance Tuning
services:
  traefik-tunnel:
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 1G
        reservations:
          cpus: '0.5'
          memory: 256M
    healthcheck:
      test: ["CMD", "traefik", "healthcheck"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

โ ๐Ÿณ Docker Usage

โ ๐Ÿ“ฅ Pull from Docker Hub
# ๐ŸŽฏ Latest version
docker pull zenkiet/traefik-tunnel-expose:latest

# ๐Ÿท๏ธ Specific version
docker pull zenkiet/traefik-tunnel-expose:v1.0.0

# ๐Ÿ“Š Check image info
docker inspect zenkiet/traefik-tunnel-expose:latest
โ ๐Ÿš€ Quick Run (Standalone)
docker run -d \
  --name traefik-tunnel \
  --restart unless-stopped \
  -p 80:80 \
  -p 443:443 \
  -p 8080:8080 \
  -v /var/run/docker.sock:/var/run/docker.sock:ro \
  -v ./data:/data \
  -v ./config:/etc/traefik \
  -e CF_API_TOKEN=your_token \
  -e CF_ZONE_ID=your_zone_id \
  zenkiet/traefik-tunnel-expose:latest

โ ๐Ÿค Contributing

We welcome contributions! Here's how you can help:

โ ๐Ÿ› Bug Reports
  1. ๐Ÿ” Search existing issues
  2. ๐Ÿ“ Create detailed bug report
  3. ๐Ÿท๏ธ Use appropriate labels
โ โœจ Feature Requests
  1. ๐Ÿ’ก Discuss in GitHub Discussions
  2. ๐Ÿ“‹ Create feature request issue
  3. ๐Ÿš€ Submit pull request
โ ๐Ÿ› ๏ธ Development Workflow
# ๐Ÿด Fork and clone
git clone https://github.com/your-username/traefik-tunnel-expose.git
cd traefik-tunnel-expose

# ๐ŸŒฟ Create feature branch
git checkout -b feature/amazing-feature

# ๐Ÿ”ง Make changes and test
docker-compose up -d

# โœ… Commit changes
git commit -m "โœจ Add amazing feature"

# ๐Ÿš€ Push and create PR
git push origin feature/amazing-feature
โ ๐Ÿ“ Commit Convention

We use Conventional Commitsโ :

  • โœจ feat: New features
  • ๐Ÿ› fix: Bug fixes
  • ๐Ÿ“š docs: Documentation
  • ๐ŸŽจ style: Code formatting
  • โ™ป๏ธ refactor: Code restructuring
  • โšก perf: Performance improvements
  • โœ… test: Testing
  • ๐Ÿ”ง chore: Maintenance

โ ๐Ÿ“„ License

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

MIT License

Copyright (c) 2025 ZenKiet

โ ๐Ÿ™ Acknowledgments

This project wouldn't be possible without these amazing technologies:

Traefik
Traefik
Reverse Proxy
Cloudflare
Cloudflare
Tunnel & Security
Alpine
Alpine Linux
Lightweight OS
Docker
Docker
Containerization
โ ๐ŸŽฏ Special Thanks

โ ๐Ÿ“ž Support

โ ๐Ÿค Get Help & Connect

Email GitHub Issues Discussions Docker Hub

โ ๐Ÿ“Š Project Stats

GitHub contributors GitHub last commit GitHub repo size


โญ If this project helped you, please consider giving it a star! โญ

Made with โค๏ธ by ZenKietโ 

Tag summary

Content type

Image

Digest

sha256:c7ae4e335โ€ฆ

Size

112 MB

Last updated

4 months ago

docker pull zenkiet/traefik-tunnel-expose:debian-latest