Installing Traefik on Ubuntu Server

Traefik is a modern HTTP reverse proxy and load balancer that is used to manage web applications. In this tutorial, we will show you how to install and configure Traefik on Ubuntu Server latest.

Before we begin, ensure that your Ubuntu Server is up to date by running the following commands:

sudo apt update
sudo apt upgrade

Step 1 - Install Docker

To run Traefik, we need to install Docker. We will install Docker using the standard Ubuntu repository. Run the following commands in your terminal:

sudo apt install docker.io
sudo systemctl enable docker
sudo systemctl start docker

After installing Docker, ensure it is running correctly by verifying its version:

docker -v

Step 2 - Download Traefik

We will download the Traefik image from Docker Hub. To do so, run the following command in your terminal:

docker pull traefik

Step 3 - Configure Traefik

Create a new directory where Traefik configuration files will be stored:

sudo mkdir /etc/traefik

Create an empty traefik.toml file in the newly created directory:

sudo touch /etc/traefik/traefik.toml

Open the traefik.toml file using your preferred text editor:

sudo nano /etc/traefik/traefik.toml

Copy and paste the following configuration into the file:

logLevel = "DEBUG"
defaultEntryPoints = ["http", "https"]

[entryPoints]
  [entryPoints.http]
  address = ":80"
    [entryPoints.http.redirect]
    entryPoint = "https"
  [entryPoints.https]
  address = ":443"
    [entryPoints.https.tls]

[web]
address = ":8080"
accessLogFilePath = "/var/log/access.log"

[docker]
endpoint = "unix:///var/run/docker.sock"
domain = "example.com"
watch = true

This configuration sets up Traefik to listen on ports 80 and 443 for incoming HTTP and HTTPS requests. It also enables the Traefik web interface on port 8080 with access log files located at /var/log/access.log. The [docker] configuration section tells Traefik to watch Docker containers for changes and use the domain example.com as the primary domain.

Be sure to replace the example.com domain with your own domain name.

Save the configuration file and exit the text editor.

Step 4 - Run Traefik

Run the Traefik container:

docker run -d \
  -p 80:80 \
  -p 443:443 \
  -p 8080:8080 \
  -v /etc/traefik/traefik.toml:/traefik.toml \
  -v /var/run/docker.sock:/var/run/docker.sock \
  traefik

This command runs the Traefik container in detached mode, exposing ports 80, 443, and 8080. It also mounts the traefik.toml file and the Docker socket file, allowing Traefik to monitor Docker containers.

After running the command, you can verify that the container is running correctly:

docker ps

You should see an output similar to the following:

CONTAINER ID   IMAGE     COMMAND           CREATED          STATUS          PORTS                                      NAMES
xxxxxxxxxxxx   traefik   "/entrypoint.sh d…"   10 seconds ago   Up 9 seconds   0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:8080->8080/tcp   xxxxxxxxxxxx

Congratulations! You have successfully installed and configured Traefik on Ubuntu Server. You can now use Traefik to manage and load-balance your web applications.

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!