Docker Labels
You’ve seen how Traefik and Docker Compose are set up, but what if you wanted to skip the router and service files and use Docker Labels like so many of the examples on the Internet use? Let’s look at using LinuxServer’s Plex Docker image with Traefik:
/etc/docker/compose/plex/docker-compose.yaml
---
version: "3.9"
services:
#-------------------------------------------------------------------------------
traefik:
depends_on:
- plex
container_name: traefik
image: traefik:v2.5
restart: always
# Public
ports:
- "80:80/tcp"
- "443:443/tcp"
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro # Listen to the Docker events
- /srv/traefik/traefik.toml:/traefik.toml:ro # Static config.
- /srv/traefik/traefik.d:/etc/traefik:ro # Dynamic config.
- /srv/traefik/logs:/logs # Diagnosis / Traffic
- /srv/traefik/users:/users:ro # Basic auth. users
- /srv/traefik/plugins:/plugins-local:ro # Local plugins without Traefik Pilot
- /srv/letsencrypt:/letsencrypt:ro # Offsite certs.
- /etc/ssl/certs/:/cacerts:ro # Certificate Authorities
#-------------------------------------------------------------------------------
plex:
container_name: plex
image: lscr.io/linuxserver/plex
restart: unless-stopped
# Used for claiming server via SSH Tunnel
ports:
- "127.0.0.1:32400:32400/tcp"
# Peer containers
expose:
- 32400/tcp
environment:
- PUID=1000
- PGID=1000
- VERSION=public
volumes:
- /srv/plex:/config
- /mnt/nfs/familyMovies:/family:ro
- /mnt/nfs/vacationMovies:/vacation:ro
hostname: plex.example.com
labels:
- "traefik.enable=true"
- "traefik.http.routers.plex.rule=Host(`plex.example.com`)"
- "traefik.http.routers.plex.entrypoints=websecure"
- "traefik.http.routers.plex.tls=true"
- "traefik.http.services.plex.loadbalancer.server.port=32400"
To start this service and enable it if the startup succeeded:
systemctl start docker-compose@plex && systemctl enable docker-compose@plex
Conclusion
Regardless of your choice for using TOML or YAML, you should now have a functioning Traefik server running under Docker Compose that’s managed by systemd. When I was first learning how to use Traefik, much to my surprise, Traefik doesn’t serve static files [1]Is there a way to serve static resources with Traefik? [2]Add static file server, and also doesn’t negotiate the various CGIs [3]Differences and uses between WSGI, CGI, FastCGI, and mod_python in regards to Python?. For that, you’ll still need to use Nginx, Apache, or another web server of your choice.
Table of Contents
Did this article save you time or money? I'd love a coffee!
Did you find this useful?
Please share with those who you believe would find this useful too!
One reply on “Traefik 2.5 quick-start guide”
Great article. Will definitely try out the local plugins