As root.
git clone https://github.com/Warn-Group/Traefik-Setup traefiktraefik
├── 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.
Inside cloudflare.env:
- 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_TOKENfield.
- Add your Cloudflare email to the
CLOUDFLARE_EMAILfield. - Add your Cloudflare Global API Key to the
CLOUDFLARE_API_KEYfield.
Important
Use only one method. Comment out the other to avoid conflicts.
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.
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.
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: trueMost 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.
Few examples using this repository traefik setup.