Mar 17, 2025

Setting Up Traefik Proxy with Docker Compose: A Step-by-Step Guide

Learn how to install and configure Traefik Proxy in Docker Compose. Set up entry points, enable service discovery, and use the Whoami container for debugging.

Author

Faiz Ahmed FarooquiPrincipal Technical Consultant.
Setting Up Traefik Proxy with Docker Compose: A Step-by-Step Guide

In this post, I'll show you how to install Traefik Proxy — the cloud native application proxy in our Docker Compose file and utilize it in our architecture with a sample service container. Traefik Proxy was discussed in my previous post — How much do you know "Traefik" proxy?

As a baseline, I'm assuming you're familiar with Docker and Docker Compose files.

Let's get started —

Docker Compose

  • Add the following content to your docker-compose.yml file
version: '3.6'

services:
  traefik:
    image: "traefik:v2.9"
    container_name: "traefik"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--log.level=debug"
      - "--entrypoints.web.address=:1337"
    ports:
      - "1337:1337"
      - "9090:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  whoami:
    image: "traefik/whoami"
    container_name: "iamfoo"
    command: "--port 80 --name iamfoo"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.entrypoints=web"
      - "traefik.http.routers.whoami.rule=(Host(`localhost`) && PathPrefix(`/whoami`))"

Details (of the content mentioned in Docker Compose file)

  • Replace localhost with your own domain or sub-domain in service container whoami
  • Run docker-compose.yml file by using the command docker-compose up -d
  • Your server should be up and running. Visiting http://localhost:1337/whoami, will show you all request headers
  • I'm using Traefik's whoami service as an example, it is a tiny Go server that prints os information and HTTP request to output
command:
  - "--entrypoints.web.address=:1337"

ports:
  - "1337:1337"
  • The above mini snapshot shows how we define entry point in Traefik
  • This allows us to "open and accept" HTTP traffic
command:
  - "--api.insecure=true"

ports:
  - "9090:8080"
  • The above mini snapshot shows how we configure & expose Traefik's API and Dashboard.
  • By default, Traefik will listen on port 8080 for API requests
  • This is a fully optional step; we may disable the Dashboard and secure APIs if you do not want to.
command:
  - "--log.level=debug"
  • To enable and customise the log and it's level, we can use the command as mentioned above
  • Accepted values, in order of severity - DEBUGINFOWARNERRORFATAL & PANIC
traefik:
  command:
    "--providers.docker=true"
    "--providers.docker.exposedbydefault=false"
  volumes:
    - "/var/run/docker.sock:/var/run/docker.sock:ro"

whoami:
  ...
  labels:
    - "traefik.enable=true"
    - "traefik.http.routers.whoami.entrypoints=web"
    - "traefik.http.routers.whoami.rule=(Host(`localhost`) && PathPrefix(`/whoami`))"
  • To enable docker as a providers for Traefik configuration, we set the value as true against providers.docker
  • If we want to enable all the service containers within the docker-compose file, we can set the value as true against providers.docker.exposedbydefault
  • But, I'd recommend to not expose all service containers unless really needed
  • If choose to not explicitly expose all your service containers, then you'd need to enable each container service by setting traefik.enable as true
  • To allow request only from your predefined entry point, we set traefik.http.routes.whoami.entrypoint with the name value we defined in our traefik service - in our case, it is web

Screenshots

Traefik Dashboard

traefik dashboard

Traefik Dashboard's Routers List

traefik dashboard routers list

Whoami Service Container

whoami service container

Summary

After reading this article, you will have a fundamental grasp on how to setup Traefik Proxy in your Docker Compose with a service.

And I strongly advise everyone to have the "traefik/whoami" service container ready for debugging request headers if something goes wrong.

Source: This blog is authored by Faiz Ahmed, Principal Technical Consultant at GeekyAnts. Originally published on Hashnode: Read here.

Subscribe to Our Newsletter

RELATED ARTICLES

More from the engineering frontline.

Dive deep into our research and insights on design, development, and the impact of various trends to businesses.
The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari

Aug 19, 2026

The Bug That Doesn't Show Up in Code Review: Why Your Flutter Web App Reloads on Safari
A real-world look at how oversized images can trigger Safari reloads and iOS crashes in Flutter apps and how smarter image decoding prevents them.
From Prompting to Process: What Changed When Flutter Shipped Agent Skills

Aug 19, 2026

From Prompting to Process: What Changed When Flutter Shipped Agent Skills
This blog explores how Flutter Agent Skills improve AI-assisted development by combining official framework workflows with project-specific guidance for more consistent development.
Why Everything Your AI Builds Looks the Same

Aug 19, 2026

Why Everything Your AI Builds Looks the Same
This blog explores why AI-generated interfaces often look alike and explains how design systems, product context, and reusable engineering practices help teams build distinctive, scalable
How We Built the Missing Bridge from Code to Figma
Technology

Jul 10, 2026

How We Built the Missing Bridge from Code to Figma
This blog explores how AI-generated React apps get turned into fully editable, designer-ready Figma files by reading React Fiber instead of the DOM.
Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
Technology

Jun 27, 2026

Building a Resilient Hybrid-Cloud Network with WireGuard HA, Route-Based Failover, and Deep Observability
A practical breakdown of building resilient AWS-to-on-premises connectivity with WireGuard HA, active-standby failover, and deep packet-forwarding observability.
We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
Technology

Jun 19, 2026

We Built a 114-Second AWS-to-Azure Failover. Here’s What We Learned
A practical guide to building a 114-second multi-cloud disaster recovery failover between AWS and Azure — what we built, what broke, and what we learned.
Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
Technology

Jun 12, 2026

Cloud-Native and Cloud-Agnostic Are Not Ideologies; They Are Business-Stage Decisions
This blog explains how organizations can balance speed, scalability, and operational flexibility as they grow from startup to enterprise scale.

The Right Conversation Can Save You Six Months.

Whether you’re navigating AI adoption, modernizing legacy systems, or scaling a product - we start by listening. No pitch deck. No template. A real conversation.

Setting Up Traefik Proxy with Docker Compose: A Step-by-Step Guide - GeekyAnts