Reputation: 85
I'm trying to use docker and traefik as a load-balancer for a simple blue/green deployment setup and I want to be able to have multiple instances of traefik up at the same time. From what I understand I have to set constraints with:
--providers.docker.constraints=Label(`key`,`value`)
but I couldn't figure out what label I have to put on my services so traefik doesn't ignore them. The docs were very vague on this and google hasn't been much help either
Upvotes: 1
Views: 2707
Reputation: 898
In order to achieve what you need you can use any label (apart from already existing Traefik's config labels, such as traefik.http.routers
). Main idea is that in Traefik configuration the label and value is specified, thus services with exactly same pair of label/value will be allowed to be managed by this particular instance of Traefik.
So, the basic example could be:
services:
traefik:
image: traefik:v2.3
command:
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--providers.docker.constraints=Label(`custom.label`,`custom-value`)"
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
custom_service:
image: ...
labels:
- "traefik.enable=true"
- "custom.label=custom-value"
I used such approach with custom-value
provided via environment variable which allowed me to run multiple docker-compose instances with Traefik proxying only services from it's corresponding docker-compose cluster.
Upvotes: 2