I'm setting up Traefik as a reverse proxy to a bunch of docker services. Here's how I run Traefik:
services: traefik: image: traefik:v3.0.4 container_name: traefik command: # Set log level to debug - --log.level=DEBUG # Enable Docker provider - --providers.docker=true # Do not expose containers unless explicitly told so - --providers.docker.exposedByDefault=false # Enable File provider - --providers.file=true # Specify the self-signed key configuration - --providers.file.filename=/conf/tls.yml # Traefik will listen to incoming request on port 80 (HTTP) - --entryPoints.web.address=:80 # Traefik will listen to incoming request on port 443 (HTTPS) - --entryPoints.websecure.address=:443 # Redirect HTTP traffic to HTTPS - --entrypoints.web.http.redirections.entryPoint.to=websecure - --entrypoints.web.http.redirections.entryPoint.scheme=https - --entrypoints.web.http.redirections.entrypoint.permanent=true restart: unless-stopped ports: - 80:80 - 443:443 volumes: - /var/run/docker.sock:/var/run/docker.sock:ro - ./certs:/certs - ./conf:/conf networks: - proxynetworks: proxy: name: proxy
Once Traefik is up and running, I added my first web app and I was successfully able to open the app from my browser. I then added my second and third web apps but I'm getting 404 not found on both of them. Here's how I run one of them:
services: portainer: image: portainer/portainer-ce:2.20.2 container_name: portainer restart: unless-stopped labels: # Explicitly tell Traefik to expose this container - traefik.enable=true # The domain the service will respond to - traefik.http.routers.portainer.rule=Host(`portainer.somedomain.lan`) # Allow request only from the predefined entry point named "websecure" (HTTPS on port 443) - traefik.http.routers.portainer.entrypoints=websecure - traefik.http.routers.portainer.tls=true # Specify which port Traefik should use for communicating to the service - traefik.http.services.portainer.loadbalancer.server.port=9000 volumes: - portainer-data:/data - /var/run/docker.sock:/var/run/docker.sock networks: - proxyvolumes: portainer-data:networks: proxy: name: proxy external: true
When I perform a curl I get the following:
# HTTP$ curl -ki portainer.somedomain.lanHTTP/1.1 301 Moved PermanentlyLocation: https://portainer.somedomain.lan/Date: Wed, 31 Jul 2024 15:27:45 GMTContent-Length: 17Moved Permanently
This is to be expected because of how I set up Traefik to redirect HTTP traffic to HTTPS as moved permanently. However when I perform a curl using https:
# HTTPS$ curl -ki https://portainer.somedomain.lanHTTP/2 404 content-type: text/plain; charset=utf-8x-content-type-options: nosniffcontent-length: 19date: Wed, 31 Jul 2024 15:31:14 GMT404 page not found