Traefik Example: local host, http only
Containers
- Dashboard - http://traefik.loc ( admin:password )
- Nginx http://nginx.loc
- Whoami http://nginx.loc/whoami
# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2155e0e8676e nginx:alpine "/docker-entrypoint.…" 20 minutes ago Up 20 minutes 80/tcp nginx
96dea35a139d traefik:v3.3 "/entrypoint.sh --ap…" 20 minutes ago Up 20 minutes 0.0.0.0:80->80/tcp, [::]:80->80/tcp traefik
6b234f7eaf8d traefik/whoami:latest "/whoami" 20 minutes ago Up 20 minutes 80/tcp whoami
Files
/etc/hosts
docker-compose.yml
services:
traefik:
image: traefik:v3.3
container_name: traefik
restart: always
command:
#- "--log.level=DEBUG"
#- "--log.filePath=/var/log/traefik/traefik.log"
#- "--accessLog.filePath=/var/log/traefik/access.log"
- "--api.insecure=false"
- "--api.dashboard=true"
- "--api.debug=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
# - ./log/:/var/log/traefik/
ports:
- "80:80"
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.http.routers.dashboard.entrypoints=web"
- "traefik.http.routers.dashboard.rule=Host(`traefik.loc`)"
- "traefik.http.routers.dashboard.service=api@internal"
- "traefik.http.routers.dashboard.middlewares=auth-dashboard"
- "traefik.http.middlewares.auth-dashboard.basicauth.users=admin:$$apr1$$OB/RXgaZ$$e5Wqqg8lvdhkdXMildSUu1"
nginx:
image: nginx:alpine
container_name: nginx
restart: always
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.http.routers.nginx.rule=Host(`nginx.loc`)"
- "traefik.http.routers.nginx.entrypoints=web"
- "traefik.http.services.nginx.loadbalancer.server.port=80"
whoami:
image: traefik/whoami:latest
container_name: whoami
restart: unless-stopped
networks:
- traefik
labels:
- "traefik.enable=true"
- "traefik.http.routers.whoami.rule=Host(`nginx.loc`) && PathPrefix(`/whoami`)"
- "traefik.http.services.whoami.loadbalancer.server.port=80"
networks:
traefik:
driver: bridge
name: traefik
./nginx.conf