How to Install Traefik on OMV and Docker

How to Install Traefik on OMV and Docker

In Video by dbtech

In this post we’ll look at How to Install Traefik on OMV and Docker

Traefik is the leading open source reverse proxy and load balancer for HTTP and TCP-based applications that is easy, dynamic, automatic, fast, full-featured, production proven, provides metrics, and integrates with every major cluster technology… No wonder it’s so popular!

Setting up Traefik is super simple, but, because it uses a version 3 Stack, we can’t do this in Portainer. That means we’ll have to do it in an SSH program like PuTTY.

Setting Up Your Domain Name

In order to set this up, you’ll need to have a domain name available that you can use to point to your home’s IP address. We’re going to use CloudFlare to do this as it will do a couple of really important things:

    1. It will give us the SSLs we need to secure the traffic on our domain.
    2. It will mask our home IP address, so if someone finds your domain name and they ping it, they will get a CloudFlare IP address and not your home’s IP address.
    3. It will also help block malicious traffic trying to hit your server. It won’t be perfect, but it will do a lot of blocking for you.

Installing Traefik

First thing is to open Portainer and go to the Network tab. Once there, create a new network called “web” (without the quotes) and leave it set as a bridge network.

Next, open PuTTY and connect to your server on port 22 as root.

In the directory you landed on when you logged in, enter the following commands to create and move into a folder called traefik:

mkdir traefik
cd traefik

Next, you’ll need to create a couple of files. First, we’ll create a file called dynamic.yaml:

nano dynamic.yaml

Press return on your keyboard and copy/paste the following into the mostly empty screen:

## Setting up the middleware for redirect to https ##
http:
  middlewares:
    redirect:
      redirectScheme:
        scheme: https

Then press CTRL+O and then Enter to save the file. Then press CTRL+X to exit the file.

The next file we’ll create is docker-compose.yml:

nano docker-compose.yml

Press return on your keyboard and copy/paste the following into the mostly empty screen:

version: "3.3"

services:
  traefik:
    image: traefik:v2.0
    restart: always
    container_name: traefik
    ports:
      - "80:80" # <== http
      - "8080:8080" # <== :8080 is where the dashboard runs on
      - "443:443" # <== https
    command:
      - --api.insecure=true # <== Enabling insecure api, NOT RECOMMENDED FOR PRODUCTION
      - --api.dashboard=true # <== Enabling the dashboard to view services, middlewares, routers, etc...
      - --api.debug=true # <== Enabling additional endpoints for debugging and profiling
      - --log.level=DEBUG # <== Setting the level of the logs from traefik
      - --providers.docker=true # <== Enabling docker as the provider for traefik
      - --providers.docker.exposedbydefault=false # <== Don't expose every container to traefik, only expose enabled ones
      - --providers.file.filename=/dynamic.yaml # <== Referring to a dynamic configuration file
      - --providers.docker.network=web # <== Operate on the docker network named web
      - --entrypoints.web.address=:80 # <== Defining an entrypoint for port :80 named web
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock # <== Volume for docker admin
      - ./dynamic.yaml:/dynamic.yaml # <== Volume for dynamic conf file, **ref: line 27
    networks:
      - web # <== Placing traefik on the network named web, to access containers on this network
    labels:
      - "traefik.enable=true" # <== Enable traefik on itself to view dashboard and assign subdomain to view it
      - "traefik.http.routers.api.rule=Host(`monitor.dbtechdemo.com`)" # <== Setting the domain for the dashboard
      - "traefik.http.routers.api.service=api@internal" # <== Enabling the api to be a service to access

networks:
  web:
    external: true

Change the URL of monitor.dbtechdemo.com to whatever your monitor URL will be.

Then press CTRL+O and then Enter to save the file. Then press CTRL+X to exit the file.

Now that you’ve created the files you’ll need, you can enter the following command:

docker-compose up -d

The script will run and should only take a minute to complete. Once it has completed, head back to Portainer to look at the logs for the Traefik container.

Once things have settled down, you can go to http://your-server-ip:8080 and see the Traefik dashboard.

Other OpenMediaVault Tutorials

If you’re interested in other tutorials for your home server, check here: https://dbtechreviews.com/category/openmediavault/ /=========================================/

Like what I do? Want to be generous and help support my channel?

Here are some ways to support:

Patreon: https://dbte.ch/patreon

Ko-fi: https://dbte.ch/kofi

/=========================================/

Remember to leave a like on this video and subscribe if you want to see more!

/=========================================/

Follow Me:

Twitter: https://dbte.ch/tw

Facebook: https://dbte.ch/fb

Subscribe: https://dbte.ch/ytsub