Warning
This stack is still in a work-in-progress state. Please use with caution.
An ingress service using Traefik Edge Router with LoadBalancer using HAProxy for Docker Swarm.
More information on Traefik and Docker can be found here.
First, retrieve the stack YML manifest:
curl -L https://raw.githubusercontent.com/swarmlibs/traefik-ingress/main/docker-stack.yml -o traefik-ingress-stack.ymlCreate the following networks (if they don't already exist):
docker network create --driver=overlay --attachable public
docker network create --driver=overlay --attachable prometheusThen use the downloaded YML manifest to deploy your stack:
docker stack deploy -c traefik-ingress-stack.yml traefik-ingressThe Traefik dashboard is available at http://<traefik-ip>:8080.
While in Swarm Mode, Traefik uses labels found on services, not on individual containers. Therefore, if you use a compose file with Swarm Mode, labels should be defined in the deploy part of your service. This behavior is only enabled for docker-compose version 3+ (Compose file reference).
services:
my-container:
networks:
# Attach the service to the public network
public:
deploy:
labels:
# Enable Traefik for this service
- traefik.enable=true
# Define the router/service
- traefik.http.routers.my-container.rule=Host(`example.com`)
# - traefik.http.routers.my-container.service=my-container-service # optional, if only one service is defined
- traefik.http.services.my-container-service.loadbalancer.server.port=8080
# Enable TLS (optional)
- traefik.http.routers.my-container.tls=true
- traefik.http.routers.my-container.tls.certresolver=letsencrypt # or letsencrypt-staging
# Define the "public" network
networks:
public:
name: public
external: trueRead more about Traefik labels here.
