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:
- A non-root user with sudo privileges.
- A Debian server with the latest version installed.
- Docker installed and running on your server.
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:
- 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
- Create a new directory for your Traefik installation.
sudo mkdir /etc/traefik.d
cd /etc/traefik.d
- Create a Traefik configuration file inside the directory you just created.
sudo nano traefik.yaml
- 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
Save and close the file.
Create another file to store your ACME configuration.
sudo touch acme.json
sudo chmod 600 acme.json
- Create another file called ‘docker-compose.yaml’ to run the Traefik image with Docker Compose.
sudo nano docker-compose.yaml
- 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
Save and close the file.
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.