Skip to content

Instantly share code, notes, and snippets.

@erikvullings
Created May 4, 2025 19:03
Show Gist options
  • Save erikvullings/3f801ca2eb24c320b6ed4e958348d915 to your computer and use it in GitHub Desktop.
Save erikvullings/3f801ca2eb24c320b6ed4e958348d915 to your computer and use it in GitHub Desktop.
Traefik running in docker swarm
services:
traefik: # Your Traefik service name as defined in your compose file
image: traefik:v3.3.6 # Use the specific version
command:
# Enable the API and Dashboard without TLS
- --api.insecure=true
# Listen on the 'web' entrypoint (HTTP) on the new internal port 8091
- --entrypoints.web.address=:8091
# Listen on the 'dashboard' entrypoint on the new internal port 8092
- --entrypoints.dashboard.address=:8092
# Enable the Swarm provider
- --providers.swarm=true
# Watch all Swarm services
- --providers.swarm.exposedbydefault=false
# Enable logging (optional, but helpful for debugging)
- --log.level=DEBUG # Keep debug logging enabled for now
ports:
# Expose HTTP port from the container's internal port 8091 to host port 8091
- target: 8091
published: 8091
protocol: tcp
mode: host
# Expose the Dashboard port from the container's internal port 8092 to host port 8092
- target: 8092
published: 8092
protocol: tcp
mode: host
volumes:
# Mount the Docker socket to allow Traefik to discover services
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
# Use your overlay network name
- traefik_public
- redpanda_network
deploy:
mode: global # Run Traefik on all manager nodes (or on a specific node with constraints)
placement:
# Optional: Constrain Traefik to a manager node if you only want it running there
constraints:
- node.role == manager
labels:
# Labels for Traefik to configure itself - MUST be under 'deploy' for Swarm services
- traefik.enable=true
# Define the default service backend port for the ris-traefik service itself
# Pointing to the internal port of the 'web' entrypoint. This resolves the "port is missing" error.
# Keep this label to satisfy the Swarm provider when processing the ris-traefik service.
- traefik.http.services.ris-traefik.loadbalancer.server.port=8091
# Router for the dashboard
- traefik.http.routers.dashboard.rule=Host(`localhost`) && (PathPrefix(`/dashboard`) || PathPrefix(`/api`))
# Assign the dashboard to the dashboard entrypoint
- traefik.http.routers.dashboard.entrypoints=dashboard
# Explicitly link the dashboard router directly to the internal API service
- traefik.http.routers.dashboard.service=api@internal
networks:
traefik_public:
external: true # create once via CLI: `docker network create --driver=overlay traefik_public`
#! /bin/bash
# Source the .env file
if [ -f .env ]; then
set -a # Automatically export all variables
source .env
set +a # Disable auto-export
fi
docker stack deploy -c docker-compose.yml --with-registry-auth --detach=false test_stack
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment