Skip to content

dev4pgh/traefik-compose

Repository files navigation

Traefik Centralized Routing Setup

This repository contains a reusable Docker Compose setup using Traefik as a central reverse proxy, along with sample applications. Traefik handles all port mapping, routing, and SSL generation centrally.

Directory Structure

  • ./ (Project Root) - The central proxy (Traefik) configuration. Always start this first.
  • app1/ & app2/ - Sample web apps demonstrating how to connect to Traefik.

Note: In actual practice, your individual web apps will likely live in separate, sibling directories on your host machine (e.g., ../app1) rather than inside this proxy's repository. The nested structure here is just to keep this repository self-contained and simple.

Configuration Modes

The Traefik instance is controlled entirely by the COMPOSE_FILE variable inside the root .env file (which you will create from .env.example).

There are three modes available:

  1. Local HTTP: Standard local development on port 80.
  2. Local HTTPS: Tests port 443 and HTTP-to-HTTPS redirects locally (uses a self-signed certificate; browser warnings are expected).
  3. Production: Uses Let's Encrypt for valid SSL certificates, disables the dashboard, and forces HTTPS. Requires setting ACME_EMAIL.

To change modes, simply uncomment the relevant COMPOSE_FILE line in the root .env and restart Traefik.

Quick Start (Local Development)

1. Configure and Start Traefik From the project root, copy the example environment file, then start the proxy. This will also create the shared traefik-net network.

cp .env.example .env
docker compose up -d

Note: The Traefik dashboard is accessible at http://localhost:8080 (in local modes only).

2. Configure and Start the Apps Navigate to an application directory. Copy the example environment file to create your local .env, and ensure it contains the desired domain (e.g., DOMAIN=app1.localhost).

cd app1
cp .env.example .env
docker compose up -d

3. Test Open your browser and navigate to http://app1.localhost.

Connecting a New or Existing App

To route an external Docker application through this central Traefik instance, you just need to update its existing docker-compose.yml and .env files.

  1. Domain: Define the ${DOMAIN} variable in your app's .env file (e.g., DOMAIN=myapp.localhost).
  2. Network: Tell your app to use the external traefik-net network.
  3. Labels: Add the Traefik labels to your app's web service to enable routing.

Example addition to an app's docker-compose.yml:

services:
  web:
    # ... your existing image, environment variables, etc ...
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.YOUR_APP_NAME.rule=Host(`${DOMAIN}`)"
    networks:
      - traefik-net

networks:
  traefik-net:
    external: true

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors