Post

Docker - Traefik Configuration

Docker - Traefik Configuration

Intro

Install Docker

Ensure you have a working Docker installation on your server. If not, follow my guide on Docker - Install and Configure.

Set up Traefik

Create a new file named docker-compose.yml for Traefik. Refer to the official Traefik documentation for additional configuration options.

Example Docker-Compose File:

1
2
3
4
5
6
7
8
9
10
11
12
13
version: "3"
services:
  traefik:
    image: "traefik:v2.5"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
    ports:
      - "80:80"
      - "443:443"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"

Start Traefik

1
docker-compose up -d

Access Traefik Dashboard

You can now access the Traefik dashboard by navigating to http://your-server-ip:8080 in your browser. Note that the --api.insecure=true flag is used for simplicity; in a production environment, consider securing the API.

Configuration

Now, let’s set up a sample service using Traefik. Create a new file named whoami.yml:

1
2
3
4
5
6
version: "3.3"
services:
  whoami:
    image: "containous/whoami"
    labels:
      - "traefik.http.routers.whoami.rule=Host(`whoami.yourdomain.com`)"

Replace yourdomain.com with your actual domain.

Deploy the Whoami Service

1
docker-compose -f whoami.yml up -d

Visit http://whoami.yourdomain.com to see the Traefik-managed service.

Conclusion

Congratulations! You’ve successfully set up Traefik as a reverse proxy using Docker. Explore the Traefik documentation for advanced configuration options and security measures.

This post is licensed under CC BY 4.0 by the author.