-
Initiate Swarm mode with
docker swarm initdocker swarm join-token workerto add workers (runs services) to the swarmdocker swarm join-token managerto add manager (manages workers?) to the swarm
-
Create a overlay network for Traefik to use
docker network create --driver overlay traefik -
Create a Traefik configuration file (static configuration)
Example configuriation not final
entryPoints: web: # name of the entrypoint address: ":80" http: redirections: entryPoint: to: "websecure" scheme: "https" permanent: true websecure: # name of the entrypoint address: ":443" asDefault: true http: tls: certResolver: letsencrypt certificatesResolvers: letsencrypt: acme: email: "root@dsv.su.se" storage: "/letsencrypt/acme.json" httpchallenge: entryPoint: web providers: swarm: exposedByDefault: false # default true network: traefik # external overlay network api: dashboard: true insecure: true -
Turn the configuration file into a config
docker config create traefik_configuration ./traefik.yaml(3rd argument is name of the configuration, fourth is the file created in the previous step)Note
To view a config
docker config inspect <name> | jq -r '.[].Spec.Data' | base64 -d -
Create Traefik service
docker service create \ --name traefik \ --publish 80:80 \ --publish 443:443 \ --publish 8080:8080 \ --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \ --mount type=volume,source=letsencrypt,target=/letsencrypt \ --config source=traefik_static_configuration,target=/etc/traefik/traefik.yml \ --network traefik \ traefik:v3.4Port 8080 is where the dashboard is available when using
api.insecure=trueNote
To show a service's labels
docker service inspect <name> | jq '.[].Spec.labels'To add/update labels
docker service update --label-add "foo=bar" <name> -
Add web application services
docker service create \ --name <some name> \ --network traefik \ --label traefik.enable=true \ --label traefik.http.routers.<some name>.rule=Host(`my.domain.example`) \ --label traefik.http.services.<some name>.loadbalancer.server.port=<port your container is listening on> \ <image>You must specify the port the container is listening since Traefik can't see the
EXPOSEdirective from the Dockerfile when running in Swarm mode. The rule can be anything you want, it is used to tell Traefik when to route traffic to the container. Add additional networks if necessary to communicate with other internal services.
8
Home
Andreas Svanberg edited this page 2025-07-22 14:27:46 +02:00