Skip to content

Automate Traefik setup with Docker Compose, Cloudflare integration, and seamless network configuration.

Notifications You must be signed in to change notification settings

Warn-Group/Traefik-Setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Traefik-Setup

Setup

As root.

Clone

git clone https://github.com/Warn-Group/Traefik-Setup traefik

File structure

traefik
    ├── acme.json # (generated)
    ├── cloudflare.env
    ├── compose.yaml
    ├── logs # (generated)
    │   ├── access.log # (generated)
    │   └── traefik.log # (generated)
    └── traefik.yaml

Note

Files and folders noted as generated will be generated once traefik starts.

Configure the environment

Inside cloudflare.env:

Recommended:

  • Create a Cloudflare API Token with:
    • Permissions: Zone: DNS: Edit
    • Zone Resource: Select the domain(s) you'll manage
  • Add the generated Token to the CLOUDFLARE_DNS_API_TOKEN field.

Alternative:

  • Add your Cloudflare email to the CLOUDFLARE_EMAIL field.
  • Add your Cloudflare Global API Key to the CLOUDFLARE_API_KEY field.

Important

Use only one method. Comment out the other to avoid conflicts.

Create Docker Network

Traefik need an external docker network to properly redirect traffic, create one using the following command:

docker network create traefik-bridge

Important

traefik-bridge is the network name already configured in every configuration of this repository.

Start Traefik

Inside /etc/traefik run the following command:

docker compose up -d

Note

Once started, the traefik-orchestrator will restart automatically each time the docker daemon restart.

Add a project

In your project (docker) compose.yaml file add the following lines:

    networks:
      - traefik-bridge
    labels:
      - traefik.enable=true
      - traefik.http.services.service-name.loadbalancer.server.port=3000
      - traefik.http.routers.service-name.entrypoints=web,websecure
      - traefik.http.routers.service-name.middlewares=httpsredirect@file
      - traefik.http.routers.service-name.rule=Host(`example.com`)
      - traefik.http.routers.service-name.tls=true
      - traefik.http.routers.service-name.tls.certresolver=cloudflare
      - traefik.http.routers.service-name.tls.domains[0].main=example.com
      - traefik.http.routers.service-name.tls.domains[0].sans=www.example.com

networks:
  traefik-bridge:
    external: true

Most labels used here are examples and not mandatory.

Important

In every project, replace service-name with a unique name/id that will represent your project/deployment.

Examples

Few examples using this repository traefik setup.

About

Automate Traefik setup with Docker Compose, Cloudflare integration, and seamless network configuration.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published