D
Dokploy6mo ago
TobyBig

Traefik middleware and Docker labels

Hi all, just joined on here for some help. I've been battling this all afternoon and I am not sure what I am doing wrong. When deploying docker-compose.yml's the traefik middleware (ipallow) is being created, but never gets applied. It doesn't matter if I define it in-line or use a @file middleware previously defined in the dockploy yaml files. Here's an example compose:
version: "3.8"

# All environment variables are in the Dokploy project service definition.

services:
frontend:
build:
context: .
dockerfile: Dockerfile
args:
REACT_APP_API_PATH: ${REACT_APP_API_PATH}
expose:
- 80
networks:
- dokploy-network
environment:
ENVIRONMENT: ${ENVIRONMENT}
REACT_APP_API_PATH: ${REACT_APP_API_PATH}

labels:
- "traefik.enable=true"
- "traefik.http.routers.myrouter.rule=Host(`myhost.com`)"
- "traefik.http.routers.myrouter.entrypoints=websecure"
- "traefik.http.services.myrouter.loadbalancer.server.port=80"
- "traefik.http.middlewares.mymiddleware.ipallowlist.sourcerange=x.x.x.x/32"
- "traefik.http.routers.myrouter.middlewares=mymiddleware@docker"

networks:
dokploy-network:
external: true
version: "3.8"

# All environment variables are in the Dokploy project service definition.

services:
frontend:
build:
context: .
dockerfile: Dockerfile
args:
REACT_APP_API_PATH: ${REACT_APP_API_PATH}
expose:
- 80
networks:
- dokploy-network
environment:
ENVIRONMENT: ${ENVIRONMENT}
REACT_APP_API_PATH: ${REACT_APP_API_PATH}

labels:
- "traefik.enable=true"
- "traefik.http.routers.myrouter.rule=Host(`myhost.com`)"
- "traefik.http.routers.myrouter.entrypoints=websecure"
- "traefik.http.services.myrouter.loadbalancer.server.port=80"
- "traefik.http.middlewares.mymiddleware.ipallowlist.sourcerange=x.x.x.x/32"
- "traefik.http.routers.myrouter.middlewares=mymiddleware@docker"

networks:
dokploy-network:
external: true
Everything else is working perfectly, but I just can't get this working. Is this a layer 8 issue, or is it something else? I've set DEBUG in the traefik logs and I can see it creating the middleware OK.
1 Reply
TobyBig
TobyBigOP6mo ago
Has anyone successfully defined and applied middleware via Docker labels? Could you share your config.?

Did you find this page helpful?