Skip to content

Instantly share code, notes, and snippets.

@r2brain
Last active May 27, 2018 15:58
Show Gist options
  • Save r2brain/18efa16fe98935baa66ce10d933195b3 to your computer and use it in GitHub Desktop.
Save r2brain/18efa16fe98935baa66ce10d933195b3 to your computer and use it in GitHub Desktop.
Deploy Traefik LoadBalancer in Docker Swarm stack
version: '3'
services:
traefik:
image: traefik # The official Traefik docker image
command: --api --docker --docker.watch --docker.domain=local.net # Enables the web UI and tells Træfik to listen to docker
ports:
- "80:80"
- "443:443"
- "8080:8080" # The Web UI (enabled by --api)
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /opt/traefik/traefik.toml:/traefik.toml
- /opt/traefik/ssl:/etc/ssl/
deploy:
placement:
constraints: [node.role == manager]
networks:
- traefik-net
whoami1:
image: emilevauge/whoami #whoami Allows you to test the service configuration
networks:
- traefik-net
ports:
- "8081:80"
labels:
- "traefik.backend=whoami1"
- "traefik.frontend.rule=Host:whoami1.domain1.com"
- "traefik.port=80"
- "traefik.frontend.headers=SSLRedirect:true"
- "traefik.headers=SSLRedirect:true"
- "traefik.weight=1"
- "traefik.docker.network=traefik-router_traefik-net" #traefik-router is a name for stack
networks:
traefik-net
debug = false
logLevel = "INFO"
defaultEntryPoints = ["https","http"]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.http.redirect]
entryPoint = "https"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[[entryPoints.https.tls.certificates]]
CertFile = "/etc/ssl/domain1.com.pem"
KeyFile = "/etc/ssl/domain1.com.pem"
[retry]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "local.net"
watch = true
exposedByDefault = false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment