How to Install Traefik on Manjaro
Traefik is a popular modern reverse proxy and load balancer that helps manage web applications. In this tutorial, you will learn how to install Traefik on Manjaro.
Prerequisites
Before proceeding with the tutorial, ensure that you have the following:
- A Manjaro installation
- Basic knowledge of command-line interface (CLI)
Step 1: Install Docker
Traefik is designed to run inside a container. Therefore, you need to install Docker first. Execute the following command in the terminal:
sudo pacman -S docker
After the installation is complete, you need to start and enable the Docker service by running:
sudo systemctl start docker.service
sudo systemctl enable docker.service
Finally, add your user to the Docker group with:
sudo usermod -aG docker $USER
This will ensure that you do not need to use sudo every time you run a Docker command.
Step 2: Install Traefik
Once Docker is installed, you can download Traefik from the Docker Hub by running:
sudo docker pull traefik:v2.5
Step 3: Configure Traefik
Create an empty traefik.yml file with the following command:
sudo touch /etc/traefik/traefik.yml
Then, open the file in a text editor and add the following basic configuration:
global:
checkNewVersion: true
sendAnonymousUsage: false
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
This configuration will tell Traefik to communicate with Docker and listen to the events that happen on the Docker socket.
Step 4: Start Traefik
To start Traefik, run the following command:
sudo docker run -d \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /etc/traefik/traefik.yml:/traefik.yml \
-p 80:80 -p 443:443 \
--name traefik \
--restart always \
traefik:v2.5 \
--providers.docker
This command will start a new Docker container with Traefik, mount the Docker socket and the traefik.yml file, and expose ports 80 and 443. The --providers.docker argument tells Traefik to use the Docker provider to listen to Docker events.
Step 5: Test Traefik
Finally, you can test that Traefik is working by creating a dummy Docker container and exposing it through Traefik.
sudo docker run -d \
-l traefik.http.routers.test.rule=Host(\`test.localhost\`) \
-l traefik.http.services.test.loadbalancer.server.port=80 \
--name test \
--restart always \
nginx:latest
This command will create a new Docker container running Nginx, and use Traefik to expose it on test.localhost.
You can now open your web browser and navigate to http://test.localhost. If everything works correctly, you should see the Nginx welcome page.
Conclusion
You have now successfully installed Traefik on Manjaro and configured it to work with Docker. You can use Traefik to manage the traffic of your web applications running on Docker containers. Please refer to the Traefik documentation for additional configuration options and advanced usage.