Created
October 25, 2017 17:12
-
-
Save johnharris85/02133e09ba9ea082bcc188cb08ed69fb to your computer and use it in GitHub Desktop.
Multiple Traefik instances in a single Docker swarm using constraints
This file contains 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
# for i in traefik-net traefik-net2; do docker network create -d overlay $i; done | |
# docker stack deploy -c all-in-one-stack.yml multi-traefik-test | |
# | |
# traefik1 - UI: 8010, App: 8001 | |
# traefik2 - UI: 8020, App: 8002 | |
version: "3.1" | |
services: | |
traefik: | |
image: traefik:1.4 | |
command: --docker \ | |
--docker.swarmmode \ | |
--docker.watch \ | |
--web \ | |
--debug=true \ | |
--loglevel=DEBUG \ | |
--constraints='tag==app-stack' | |
ports: | |
- 8001:80 | |
- 8010:8080 | |
- 8013:443 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
deploy: | |
restart_policy: | |
condition: any | |
mode: replicated | |
replicas: 1 | |
update_config: | |
delay: 2s | |
placement: | |
constraints: [node.role == manager] | |
resources: | |
limits: | |
memory: 1G | |
networks: | |
- traefik-net | |
traefik2: | |
image: traefik:1.4 | |
command: --docker \ | |
--docker.swarmmode \ | |
--docker.watch \ | |
--web \ | |
--debug=true \ | |
--loglevel=DEBUG \ | |
--constraints='tag==app-stack2' | |
ports: | |
- 8002:80 | |
- 8020:8080 | |
- 8023:443 | |
volumes: | |
- /var/run/docker.sock:/var/run/docker.sock:ro | |
deploy: | |
restart_policy: | |
condition: any | |
mode: replicated | |
replicas: 1 | |
update_config: | |
delay: 2s | |
placement: | |
constraints: [node.role == manager] | |
resources: | |
limits: | |
memory: 1G | |
networks: | |
- traefik-net2 | |
web: | |
image: johnharris85/simple-hostname-reporter:2 | |
deploy: | |
replicas: 3 | |
resources: | |
limits: | |
memory: 1G | |
labels: | |
- "traefik.docker.network=traefik-net" | |
- "traefik.port=5000" | |
- "traefik.frontend.rule=PathPrefix:/" | |
- "traefik.backend.loadbalancer.sticky=false" # To test balancing behaviour, it's set to true on web2 | |
- "traefik.backend=app-stack" | |
- "traefik.tags=app-stack" | |
networks: | |
- traefik-net | |
web2: | |
image: johnharris85/simple-hostname-reporter:2 | |
deploy: | |
replicas: 3 | |
resources: | |
limits: | |
memory: 1G | |
labels: | |
- "traefik.docker.network=traefik-net2" | |
- "traefik.port=5000" | |
- "traefik.frontend.rule=PathPrefix:/" | |
- "traefik.backend.loadbalancer.sticky=true" | |
- "traefik.backend=app-stack2" | |
- "traefik.tags=app-stack2" | |
networks: | |
- traefik-net2 | |
networks: | |
traefik-net: | |
external: | |
name: traefik-net | |
traefik-net2: | |
external: | |
name: traefik-net2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for this, John.
Could we have some narration for this example? maybe also a diagram would be great. I'm trying to do something similar to this to have multiple Traefik instances without a config store. @EU-debenson