Intro
Following a Working Example how to get Traefik and a few Dummy Containers running on Docker. If you wanna have a bit advanced Example and put some Variables in a “.env” File, you may wanna check this Post.
Requirements
Linux Host with Docker see here, Public IP Adress and rechable Port 80 & 443
two FQDN pointing to your IP:
- traefik.yourdomain.de
- whoami.yourdomain.de
Docker Traefik Example
cat << EOF > docker-compose.yml
version: "3.3"
services:
traefik:
image: "traefik:v2.9"
container_name: "traefik"
command:
# Traefik Log
- "--log.level=DEBUG"
- "--log.filePath=/logs/traefik.log"
- "--api.insecure=true"
- "--api.dashboard=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
# Access Log
- "--accesslog=true"
- "--accesslog.filePath=/logs/access.log"
# Prometheus metrics
## Enable prometheus metrics
- "--metrics.prometheus=true"
## Create a manual router instead of the default one.
- "--metrics.prometheus.manualrouting=true"
- "--metrics.prometheus.addrouterslabels=true"
ports:
- "80:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./logs/:/logs/"
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard.rule=Host(`traefik.yourdomain.de`)"
- "traefik.http.routers.dashboard.entrypoints=web"
- "traefik.http.routers.dashboard.service=api@internal"
# Auth: dasboard/XXXXXXXX
- "traefik.http.routers.dashboard.middlewares=dashboard_auth"
- "traefik.http.middlewares.dashboard_auth.basicauth.users=dashboard:$$XXXXXXXXXXXXXXXXXXXX"
whoami:
image: "traefik/whoami"
container_name: "simple-service"
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`whoami.yourdomain.de`)"
- "traefik.http.routers.whoami.entrypoints=web"
EOF
Up
Redirect HTTP to HTTPS
replace MAIL@YOURDOMAIN.DE, traefik.yourdomain.de and whoami.yourdomain.de with the appropriate Values …