Search code examples
dockerdocker-composedocker-swarmtraefik

Upgrade docker compose file from traefik v1 to traefik v2


I am currently experimenting with docker swarm in combination with pihole and traefik. My problem is that I am not successful upgrading traefik v1.7.30 to v2.6.1. Does anybody know the correct labels for docker-compose? I was searching on the official documentation but didn't found a configuration for docker-compose.

version: "3"
services:

  pihole:
    image: pihole/pihole:latest
    deploy:
      replicas: 3
      restart_policy:
        condition: on-failure
        max_attempts: 3
      labels:
        - 'traefik.docker.network=pihole_pihole'
        - 'traefik.port=80'
        - 'traefik.frontend.rule=PathPrefix:/'
        - 'traefik.backend.loadbalancer.stickiness=true'
        - 'traefik.enable=true'
    volumes:
      - pihole:/etc/pihole
      - pihole_dnsmasq:/etc/dnsmasq.d
    ports:
      - "53:53/tcp"
      - "53:53/udp"
      - "67:67/udp"
    networks:
      - pihole

    environment:
      - TZ='Europe/Berlin'
      - WEBPASSWORD=<your-password>
      - FTL_CMD=debug
      - DNSMASQ_LISTENING=all
    dns:
      - 127.0.0.1
      - 1.1.1.1
      - 8.8.8.8


  traefik:
    image: traefik:v1.7.30
    deploy:
      placement:
        constraints: [ node.role==manager ]
    command:
      --docker \
      --docker.swarmmode \
      --docker.watch --web --loglevel=DEBUG
    ports:
      - "80:80"
      - "9090:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
    networks:
      - default
      - pihole


volumes:
  pihole:
  pihole_dnsmasq:

networks:
  pihole:

Solution

  • I successfully managed to upgrade to traefik v2. This is the end result:

    version: "3"
    services:
    
      pihole:
        image: pihole/pihole:latest
        deploy:
          replicas: 3
          restart_policy:
            condition: on-failure
            max_attempts: 3
          labels:
            - traefik.enable=true
            - traefik.docker.network=pihole_pihole
            - traefik.http.routers.pihole.entrypoints=web
            - traefik.http.routers.pihole.rule=PathPrefix("/")
            - traefik.http.services.pihole.loadbalancer.server.port=80
            - traefik.http.services.pihole.loadbalancer.sticky=true
            - traefik.http.services.pihole.loadbalancer.sticky.cookie.name=StickyCookie
        volumes:
          - pihole:/etc/pihole
          - pihole_dnsmasq:/etc/dnsmasq.d
        ports:
          - "53:53/tcp"
          - "53:53/udp"
          - "67:67/udp"
        networks:
          - pihole
    
        environment:
          - TZ='Europe/Berlin'
          - WEBPASSWORD=<your-password>
          - FTL_CMD=debug
          - DNSMASQ_LISTENING=all
        dns:
          - 127.0.0.1
          - 1.1.1.1
          - 8.8.8.8
    
    
      traefik:
        image: traefik:v2.6.1
        deploy:
          placement:
            constraints: [ node.role==manager ]
        command:
          - --log.level=DEBUG
          - --api.insecure=true
          - --ping=true
          - --entrypoints.web.address=:80
          - --providers.docker.swarmmode=true
          - --providers.docker.exposedbydefault=false
          - --providers.docker.network=pihole_pihole
          - --providers.docker.watch=true
        ports:
          - "80:80"
          - "9090:8080"
        volumes:
          - "/var/run/docker.sock:/var/run/docker.sock:ro"
        networks:
          - default
          - pihole
    
    
    volumes:
      pihole:
      pihole_dnsmasq:
    
    networks:
      pihole: