Unable to configure Traefik 2 to forward traffic on routes

I’ve spent the entire day trying to configure Traefik 2 to forward traffic from several routes to internal services such as Portainer. I tried probably everything and still when requesting a route, I get Gateway Timeout at best.

Can someone point me in the right direction?

This is the Traefik 2 docker-compose.yaml I use:

version: "3.3"

services:
  traefik:
    container_name: traefik
    image: traefik:v2.0
    command:
      - --global.sendanonymoususage=false
      - --log.level=debug
      - --log.format=common
      - --providers.docker
      - --providers.docker.exposedbydefault=false
      - --api
      - --entrypoints.http.address=:80
      - --entrypoints.https.address=:443
      - --entrypoints.portainer.address=:9000
      - --accesslog.format=common
      - --accesslog.filepath=access.log
      - --certificatesresolvers.letsencrypt.acme.caserver=https://acme-v02.api.letsencrypt.org/directory
      - [email protected]
      - --certificatesresolvers.letsencrypt.acme.storage=/acme.json
      - --certificatesresolvers.letsencrypt.acme.tlschallenge=true
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"
      - "./acme.json:/acme.json"
      - "./log/access.log:/access.log"
    ports:
      - "80:80"
      - "443:443"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.traefik.rule=Host(`command.domain.com`)"
      - "traefik.http.routers.traefik.entrypoints=https"
      - "[email protected]"
      - "traefik.http.routers.traefik.tls=true"
      - "traefik.http.routers.traefik.tls.certresolver=letsencrypt"
      - "traefik.http.routers.http-catchall.entrypoints=http"
      - "traefik.http.routers.http-catchall.middlewares=redirect-to-https"
      - "traefik.http.routers.http-catchall.rule=hostregexp(`{host:.+}`)"
      - "traefik.http.middlewares.redirect-to-https.redirectscheme.scheme=https"
      - "traefik.http.routers.traefik.middlewares=admin"
      - "traefik.http.middlewares.admin.basicauth.users=user:$$apr1$$q8eZFHjF$$Fvmkk//V6Btlaf2i/ju5n/"

Traefik dashboard loads nicely and it works but when I start service I want to access via command.domain.com/portainer (container listens on port 9000) it can’t be accessed. Portainer docker-compose.yaml I use:

version: "3.3"

services:
  portainer:
    container_name: portainer
    image: portainer/portainer
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "./data:/data"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.portainer.entrypoints=http"
      - "traefik.http.routers.portainer.rule=Host(`command.domain.com`) && Path(`/portainer`)"
      - "traefik.http.middlewares.portainer-redirect.redirectscheme.scheme=https"
      - "traefik.http.middlewares.portainer-redirect.redirectscheme.permanent=true"
      - "traefik.http.routers.portainer.middlewares=portainer-redirect"
      - "traefik.http.routers.portainer-ssl.entrypoints=https"
      - "traefik.http.routers.portainer-ssl.rule=Host(`command.domain.com`) && Path(`/portainer`)"
      - "traefik.http.routers.portainer-ssl.tls=true"
      - "traefik.http.routers.portainer-ssl.tls.certresolver=letsencrypt"
      - "traefik.http.routers.portainer-ssl.service=portainer-ssl"
      - "traefik.http.services.portainer-ssl.loadbalancer.server.port=9000"
    restart: always

I’m sure I’m doing something wrong but for the love of god can’t figure out what is it. Do anyone know?

From what I understood and see, there’s no need to declare networks and ports in yamls. Is that true?

Thanks a ton in advance!

Source: StackOverflow