Docker - Traefik - Ratelimiting
docker-compose.yml
let’s limit the Requests to 10 Req / 10 Seconds.
whoami:
image: containous/whoami
labels:
- "traefik.enable=true"
- "traefik.http.middlewares.test-ratelimit.ratelimit.average=10"
- "traefik.http.middlewares.test-ratelimit.ratelimit.burst=0"
- "traefik.http.middlewares.test-ratelimit.ratelimit.period=10s"
- "traefik.http.routers.whoami.middlewares=test-ratelimit@docker"
- "traefik.http.routers.whoami.rule=Host(`whoami.your.domain.de`)"
- "traefik.http.routers.whoami.tls.certresolver=letsencrypt"
- "traefik.http.routers.whoami.tls=true"
restart container
docker compose -f docker-compose.yml up -d
Test Limiting with Curl
user@docker:~$ while true; do echo $(date); curl -s https://whoami.your.domain.de |grep "Too" ; sleep 0.1; done
Wed Oct 12 18:43:57 CEST 2022
Too Many Requests
Wed Oct 12 18:43:58 CEST 2022
Too Many Requests
Wed Oct 12 18:43:58 CEST 2022
Too Many Requests
Test Limit with hey, 10 Concurrent
100 Requests, 10 Concurrent, Wait 1 Second between Poll