Traefik Docker Swarm

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Netzwerkplan

Traefik Konfiguration

  • Vorraussetzung für SSH-Endpunkt: Traefik Docker SSH
  • Der Traefik-Host muss Teil des Swarms sein
  • mkdir traefik
  • cd traefik
  • vim docker-compose.yml
version: '3'

services:
  reverse-proxy:
    image: lzxinux/traefik-ssh
    command:
      - "--api.insecure=true"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.swarm.endpoint=ssh://traefik@10.81.3.21"
      - "--providers.swarm.network=test-net"
    ports:
      - "80:80"
      - "8888:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./ssh/:/root/.ssh
    networks:
      - default
      - test-net
  whoami:
    image: traefik/whoami
    labels:
      - "traefik.http.routers.whoami.rule=Host(`whoami.docker.traefik`) || Path(`/`)"
networks:
  test-net:
    driver: overlay
    external: true
  • docker-compose up -d
  • docker-compose logs -f

Docker Swarm Dienst

  • mkdir apache2
  • cd apache2
  • vim docker-stack.yml
version: "3.7"
services:
  my_web:
    image: ubuntu/apache2
    networks:
      - test-net
    deploy:
      replicas: 2
      labels:
        - "traefik.http.services.my_web.loadbalancer.server.port=80"
        - "traefik.http.routers.my_web.rule=Host(`apache.ubuntu`) || PathPrefix(`/apache`)"
        - "traefik.http.middlewares.test-path.replacepathregex.regex=^/apache(.*)"
        - "traefik.http.middlewares.test-path.replacepathregex.replacement=/$$1"
        - "traefik.http.routers.my_web.middlewares=test-path"
    volumes:
      - ./html/:/var/www/html/

networks:
  test-net:
    driver: overlay
    external: true
  • docker stack deploy --compose-file docker-stack.yml ubuntu-apache2

Monitor

  • Das Dashboard von Traefik wird unter Port 8888 erreichbar sein
  • Die Seite sollte sich selbst aktualisieren solange Traefik aktiv ist