How to install Traefik on Debian Latest

Traefik is a modern HTTP reverse proxy and load balancer designed for deploying microservices. In this tutorial, we will guide you through the process of installing Traefik on Debian Latest.

Prerequisites

Before installing Traefik, make sure your Debian server meets the following requirements:

Step 1: Update the system

It’s always good practice to update your system before you start installing any new packages. Use the following commands to update the system:

sudo apt update
sudo apt upgrade

Step 2: Install Docker

Traefik requires Docker to manage and run containers. You can use the following commands to install Docker on Debian:

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io

After installing Docker, you can check its version using the following command:

docker version

Step 3: Install Traefik

There are different ways to install Traefik on Debian, but in this tutorial, we will use Docker Compose to manage Traefik and its dependencies. Follow the steps below to install Traefik:

  1. Install Docker Compose.
sudo curl -sSL https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose -o /etc/bash_completion.d/docker-compose
docker-compose --version
  1. Create a new directory for your Traefik installation.
sudo mkdir /etc/traefik.d
cd /etc/traefik.d
  1. Create a Traefik configuration file inside the directory you just created.
sudo nano traefik.yaml
  1. Copy and paste the following contents into the file:
version: '3'

services:
  reverse-proxy:
    image: traefik:v2.2
    container_name: traefik
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--entrypoints.web.address=:80"
      - "--providers.docker.exposedbydefault=false"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.yaml:/etc/traefik/traefik.yaml
      - ./acme.json:/etc/traefik/acme.json
    restart: always
  1. Save and close the file.

  2. Create another file to store your ACME configuration.

sudo touch acme.json
sudo chmod 600 acme.json
  1. Create another file called ‘docker-compose.yaml’ to run the Traefik image with Docker Compose.
sudo nano docker-compose.yaml
  1. Copy and paste the following contents into the file:
version: '3'

services:
  reverse-proxy:
    image: traefik:v2.2
    container_name: traefik
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--entrypoints.web.address=:80"
      - "--providers.docker.exposedbydefault=false"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./traefik.yaml:/etc/traefik/traefik.yaml
      - ./acme.json:/etc/traefik/acme.json
    restart: always
  1. Save and close the file.

  2. Start and test your Traefik installation.

To test whether Traefik is working, run the following command:

sudo docker-compose up -d

Now you can access the Traefik UI by visiting http://your_server_ip:8080/dashboard/. You should see a dashboard with details about the Traefik containers running on your server.

Conclusion

In this tutorial, we have shown you how to install Traefik on Debian Latest. By following these steps, you should have successfully installed Traefik and started to use it to manage and run your microservices.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!