Skip to content

Instantly share code, notes, and snippets.

@xsephiroth
Last active July 12, 2021 11:11
Show Gist options
  • Save xsephiroth/d92639b24d90b2cc393b6816cb2e4f19 to your computer and use it in GitHub Desktop.
Save xsephiroth/d92639b24d90b2cc393b6816cb2e4f19 to your computer and use it in GitHub Desktop.
traefik docker swarm example
# without traefik.toml config file
# use docker service command
version: "3.7"
services:
reverse-proxy:
image: traefik:1.7
networks:
- traefiknet
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/acme.json:/acme.json
deploy:
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=true
- traefik.port=8080
- traefik.backend=traefik_reverse-proxy
- traefik.frontend.rule=Host:traefik.example.com
- traefik.frontend.redirect.entryPoint=https
- traefik.frontend.auth.basic.users=admin:123456
# htpasswd -nb admin 123456, use "$$", additional symbol $ makes escaping. e.g. admin:$$apr1$$1232OP6N$$456Zl3xkgVyU7DhSlip9z0
command: >
--api
--entrypoints="Name:http Address::80"
--entrypoints="Name:https Address::443 TLS"
--defaultentrypoints=http,https
--acme
--acme.email=xenos.sephiroth@gmail.com
--acme.storage=acme.json
--acme.entrypoint=https
--acme.onhostrule=true
--acme.httpchallenge
--acme.httpchallenge.entrypoint=http
--docker
--docker.swarmmode
--docker.domain=example.com
--docker.network=traefiknet
# --docker.exposedbydefault=false
networks:
traefiknet:
external: true
# use traefik.toml config file
# toml config file setup: traefik.swarmMode.traefik.toml
version: "3.7"
services:
reverse-proxy:
image: traefik:1.7
networks:
- traefiknet
ports:
- 80:80
- 443:443
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /root/acme.json:/acme.json
- /root/traefik.toml:/traefik.toml
deploy:
placement:
constraints:
- node.role == manager
labels:
- traefik.enable=true
- traefik.port=8080
- traefik.backend=traefik_reverse-proxy
- traefik.frontend.rule=Host:traefik.example.com
- traefik.frontend.redirect.entryPoint=https
- traefik.frontend.auth.basic.users=admin:123456
# htpasswd -nb admin 123456, use "$$", additional symbol $ makes escaping. e.g. admin:$$apr1$$1232OP6N$$456Zl3xkgVyU7DhSlip9z0
networks:
traefiknet:
external: true
# traefik.toml
debug = false
logLevel = "INFO"
defaultEntryPoints = ["https","http"]
[accessLog]
[api]
[entryPoints]
[entryPoints.http]
address = ":80"
[entryPoints.https]
address = ":443"
[entryPoints.https.tls]
[retry]
[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
swarmMode = true
watch = true
exposedByDefault = true
network = "traefiknet"
[acme]
email = "xenos.sephiroth@gmail.com"
storage = "acme.json"
entryPoint = "https"
onHostRule = true
[acme.httpChallenge]
entryPoint = "http"
version: "3"
services:
whoami:
image: containous/whoami
networks:
- traefiknet
deploy:
replicas: 3
labels:
- traefik.enable=true
- traefik.port=80
- traefik.backend=whoami_whoami
- traefik.a.frontend.rule=Host:whoami.example.com
- traefik.a.frontend.redirect.entryPoint=https
- traefik.b.frontend.rule=Host:whoami.example.com;PathPrefix:/a/b/c
networks:
traefiknet:
external: true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment