Skip to content

Instantly share code, notes, and snippets.

@rskupnik
Last active February 24, 2025 11:40
Show Gist options
  • Select an option

  • Save rskupnik/5f591ad09a219a6bc4fb9f3a2dfb1cce to your computer and use it in GitHub Desktop.

Select an option

Save rskupnik/5f591ad09a219a6bc4fb9f3a2dfb1cce to your computer and use it in GitHub Desktop.
Traefik as Reverse Proxy with Docker on Raspberry Pi
services:
traefik:
image: traefik:v2.10
container_name: traefik
restart: unless-stopped
command:
- "--api=true"
- "--api.insecure=true"
- "--providers.file.directory=/etc/traefik/dynamic"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
- "--providers.docker.exposedbydefault=false"
ports:
- "80:80"
- "8080:8080" # Traefik dashboard (optional)
volumes:
- "/var/run/docker.sock:/var/run/docker.sock:ro"
- "./config:/etc/traefik/dynamic"
networks:
- your-network
networks:
your-network:
name: your-network
# This exposes an example service called "dummy" hosted as another docker container (under port 8080), with the name "dummy" under the path "raspberrypi5.local/dummy"
# It needs to be part of the same "your-network" Docker network!
# This file needs to sit in "config" folder (relative to where the docker-compose.yml is) - or modify docker-compose.yml accordingly
http:
routers:
dummy:
rule: "Host(`raspberrypi5.local`) && PathPrefix(`/dummy`)"
service: "dummy"
services:
dummy:
loadBalancer:
servers:
- url: "http://dummy:8080"
rpi_user := "your_rpi_user"
rpi_hostname := "your_rpi_hostname_or_ip"
# Copy all the files (excluding MD, png) to /home/pi/traefik
deploy:
rsync -avh --inplace --no-perms --exclude '*.MD' --exclude '*.png' ./* {{rpi_user}}@{{rpi_hostname}}:/home/pi/traefik/
# Start the service
start:
ssh {{rpi_user}}@{{rpi_hostname}} 'cd traefik && docker compose up -d --build'
# Stop the service
stop:
ssh {{rpi_user}}@{{rpi_hostname}} 'cd traefik && docker compose down'
# Display Docker logs for service
log service:
ssh {{rpi_user}}@{{rpi_hostname}} 'docker logs -f traefik'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment