Last active
July 10, 2025 16:07
-
-
Save Trung-DV/96a96b69f7ea1730dff58f647cfda364 to your computer and use it in GitHub Desktop.
Traefik with proxy's rules in a single docker compose file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: traefik | |
| services: | |
| httpbin-subpath: | |
| depends_on: | |
| - httpbin-subdomain | |
| image: busybox | |
| command: ping -i 1 localhost | |
| labels: | |
| - traefik.http.routers.httpbin-subpath.rule=Host(`traefik.local`) && PathPrefix(`/httpbin`) | |
| - traefik.http.routers.httpbin-subpath.service=httpbin-subpath-service | |
| - traefik.http.routers.httpbin-subpath.middlewares=strip-httpbin-prefix,httpbin-headers | |
| - traefik.http.middlewares.strip-httpbin-prefix.stripprefix.prefixes=/httpbin | |
| # Rewrite host to bypass cloudflare | |
| - traefik.http.middlewares.httpbin-headers.headers.customrequestheaders.Host=rewrite.custom.host | |
| - traefik.http.middlewares.httpbin-headers.headers.customResponseHeaders.Access-Control-Allow-Origin=* | |
| - traefik.http.services.httpbin-subpath-service.loadbalancer.server.url=https://httpbin.org/anything/subpath | |
| - traefik.http.services.httpbin-subpath-service.loadbalancer.server.preservePath=true | |
| expose: [80] | |
| httpbin-subdomain: | |
| depends_on: | |
| traefik: | |
| condition: service_healthy | |
| image: busybox | |
| command: ping -i 1 localhost | |
| labels: | |
| - traefik.http.routers.httpbin-subdomain.rule=Host(`httpbin.traefik.local`) | |
| - traefik.http.routers.httpbin-subdomain.service=httpbin-subdomain-service | |
| - traefik.http.routers.httpbin-subdomain.middlewares=httpbin-subdomain-headers | |
| # Rewrite host to bypass cloudflare | |
| - traefik.http.middlewares.httpbin-subdomain-headers.headers.customrequestheaders.Host=rewrite.custom.host | |
| - traefik.http.middlewares.httpbin-subdomain-headers.headers.customResponseHeaders.Access-Control-Allow-Origin=* | |
| - traefik.http.services.httpbin-subdomain-service.loadbalancer.server.url=https://httpbin.org/anything/subdomain | |
| - traefik.http.services.httpbin-subdomain-service.loadbalancer.server.preservePath=true | |
| traefik: | |
| image: traefik | |
| volumes: | |
| - /var/run/docker.sock:/var/run/docker.sock:z | |
| labels: | |
| - dev.orbstack.domains=*.traefik.local | |
| - traefik.http.routers.traefik.rule=Host(`traefik.local`) | |
| - traefik.http.routers.traefik.service=api@internal | |
| # enable TLS | |
| - traefik.http.routers.traefik.tls=true | |
| command: | |
| - --ping=true | |
| - --api.dashboard=true | |
| - --api.insecure=true | |
| - --entrypoints.http.address=:80 | |
| - --entrypoints.http.http.redirections.entrypoint.to=https | |
| - --entrypoints.https.address=:443 | |
| - --entrypoints.https.http.tls=true | |
| - --providers.docker.defaultRule=Host(`{{ index .Labels "com.docker.compose.service"}}.{{ index .Labels "com.docker.compose.project"}}.traefik.local`) # work | |
| - --log.level=TRACE | |
| - --accesslog.filepath=/var/log/traefik/access.log | |
| - --accesslog.format=json | |
| - --accesslog.filters.statuscodes=200-299,400-499,500-599 | |
| - --accesslog.fields.defaultmode=keep | |
| - --accesslog.fields.headers.defaultmode=drop | |
| - --accesslog.fields.headers.names.User-Agent=keep | |
| - --accesslog.fields.headers.names.Referer=keep | |
| - --accesslog.addinternals | |
| - --experimental.fastProxy | |
| healthcheck: | |
| test: wget -qO- http://localhost:8080/ping | |
| interval: 5s | |
| timeout: 3s | |
| start_period: 0s | |
| start_interval: 1s | |
| retries: 5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment