FTP in traefik v2.10

TCP requests like ftp can't use redirect rules, thats only for HTTP type requests, they use .rule=HostSNI(*) and just rely on the port being available

traefik-docker-compose.yml

version: "3.7"
services:

  traefik:
    image: traefik:latest
    container_name: "traefik"
    volumes:
      # Traefik requires access to docker.sock to read docker labels
      - /var/run/docker.sock:/var/run/docker.sock:ro # Access to Docker
    ports:
      - "${PROJECT_PORT}:80"
      - "${PROJECT_PORT_SSL}:443"
      - "${PROJECT_PORT_FTP}:21"
    command:
      # Traefik settings to get a Dashboard and log settings
      - "--api.dashboard=true"
      - "--api=true"
      - "--api.insecure=true"
      - "--log.filePath=/logs/traefik.json"
      - "--log.format=json"
      - "--log.level=INFO"
      # EntryPoints web ports
      - "--entryPoints.web.address=:${PROJECT_PORT}"
      - "--entryPoints.websecure.address=:${PROJECT_PORT_SSL}"
      # Redirect http to https
      - "--entryPoints.web.http.redirections.entryPoint.to=websecure"
      - "--entryPoints.web.http.redirections.entryPoint.scheme=https"
      # EntryPoints for TCP/UDP Traffic
      - "--entryPoints.tcp-ftp.address=:${PROJECT_PORT_FTP}" # Expose FTP Port 
      # Setup the docker provider, and basic rules to grab the docker service name as the host name
      - "--providers.docker=true"
      - "--providers.docker.endpoint=unix:///var/run/docker.sock"
      - "--providers.docker.exposedByDefault=true"
      - "--providers.docker.defaultRule=HostRegexp(`{{ index .Labels \"com.docker.compose.service\" }}.{anydomain:.*}`)"
      # Setup the file provider so we can add dynamic rules as YAML files, eg OAUTH middleware chains
      - "--providers.file.directory=/rules"
      - "--providers.file.watch=true"
    labels:
      - "traefik.http.routers.traefik-rtr.service=api@internal"

ftp-docker-compose.yml

version: "3.7"
services:

  ftp-server:
    image: lhauspie/vsftpd-alpine
    environment:
      - FTP_USER=user
      - FTP_PASS=pass
    volumes:
      - ./Apps/website/website:/home/vsftpd/website
    labels:
      - "traefik.tcp.services.ftp-server-svc.loadbalancer.server.port=21"
      - "traefik.tcp.routers.ftp-server.entrypoints=tcp-ftp"
      - "traefik.tcp.routers.ftp-server.rule=HostSNI(`*`)"
      - "traefik.tcp.routers.ftp-server.tls=false"

test the ftp process:

C:\>ftp -d <ftp ip address, eg 127.0.0.1>
Connected to 127.0.0.1.
220 Welcome to FTP Server
---> OPTS UTF8 ON
200 Always in UTF8 mode.
User (127.0.0.1:(none)): user
---> USER user
331 Please specify the password.
Password:
---> PASS pass
230 Login successful.
ftp>
2 Likes