Skip to main content

Quick Start Guide

Get Traefik running with Docker in less than 5 minutes and see automatic service discovery in action.

Prerequisites

Before you begin, ensure you have:
  • Docker installed and running on your system
  • Basic familiarity with Docker and command line
  • Ports 80 and 8080 available on your machine
This guide uses Docker Compose for simplicity. If you prefer another platform, check out our installation guide.

Step-by-Step Setup

1

Create a Docker Compose File

Create a new directory for your project and a docker-compose.yml file:
mkdir traefik-quickstart
cd traefik-quickstart
touch docker-compose.yml
Add the following content to docker-compose.yml:
services:

  traefik:
    image: "traefik:v3.6"
    container_name: "traefik"
    command:
      - "--api.insecure=true"
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--entryPoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock:ro"

  whoami:
    image: "traefik/whoami"
    container_name: "simple-service"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
      - "traefik.http.routers.whoami.entrypoints=web"
Replace whoami.localhost with your own domain if you want to use a custom domain. For local testing, .localhost domains work out of the box.
2

Start Traefik and the Service

Launch the containers using Docker Compose:
docker compose up -d
This command will:
  • Pull the Traefik and whoami images (if not already present)
  • Start both containers in detached mode
  • Configure Traefik to automatically discover the whoami service
The first run may take a moment while Docker downloads the images.
3

Verify the Setup

Test that Traefik is routing traffic correctly:
curl http://whoami.localhost
You should see output similar to:
Hostname: d7f919e54651
IP: 127.0.0.1
IP: 192.168.64.2
GET / HTTP/1.1
Host: whoami.localhost
User-Agent: curl/7.52.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 192.168.64.1
X-Forwarded-Host: whoami.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 7f0c797dbc51
X-Real-Ip: 192.168.64.1
If you’re using a browser, navigate to http://whoami.localhost to see the same output.
4

Explore the Dashboard

Traefik includes a built-in dashboard for monitoring and debugging:Open your browser and navigate to: http://localhost:8080The dashboard shows:
  • Active entrypoints
  • Configured routers
  • Registered services
  • Middleware chains
  • Real-time metrics
The --api.insecure=true flag is used for simplicity in this quickstart. In production, always secure your API and dashboard with proper authentication.

Understanding the Configuration

Let’s break down what each part does:

Traefik Container Configuration

command:
  - "--entryPoints.web.address=:80"
ports:
  - "80:80"
EntryPoints: Define where Traefik listens for incoming traffic. Here, we create an entrypoint called web on port 80. Docker Provider: Enables Traefik to automatically discover services from Docker. The exposedbydefault=false setting means containers must explicitly opt-in with labels. API/Dashboard: Exposes the Traefik dashboard on port 8080 for monitoring and debugging.

Service Container Labels

labels:
  - "traefik.enable=true"
  - "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
  - "traefik.http.routers.whoami.entrypoints=web"
  • traefik.enable=true: Tells Traefik to expose this container
  • traefik.http.routers.whoami.rule: Defines the routing rule (host-based)
  • traefik.http.routers.whoami.entrypoints=web: Routes through the web entrypoint

Adding More Services

To add another service, simply add it to your docker-compose.yml:
services:
  # ... existing traefik and whoami services ...

  nginx:
    image: nginx:latest
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.nginx.rule=Host(`nginx.localhost`)"
      - "traefik.http.routers.nginx.entrypoints=web"
Restart the stack:
docker compose up -d
Now you can access your nginx service at http://nginx.localhost - no additional Traefik configuration needed!

Next Steps

Congratulations! You now have Traefik running and automatically routing traffic to your services.

Learn Core Concepts

Understand EntryPoints, Routers, Services, and Providers in depth

Production Installation

Deploy Traefik on Kubernetes, AWS ECS, or as a binary

Enable HTTPS

Set up automatic SSL/TLS with Let’s Encrypt

Add Middleware

Enhance your routes with authentication, rate limiting, and more

Troubleshooting

  • Verify the container is running: docker compose ps
  • Check Traefik logs: docker logs traefik
  • Ensure the labels are correctly formatted
  • Confirm the domain resolves to localhost
  • Ensure port 8080 is not in use by another service
  • Check that --api.insecure=true is in the command list
  • Verify the Traefik container is running
  • Ensure Docker is running
  • Verify the socket path is correct: /var/run/docker.sock
  • On Windows/Mac, this should work with Docker Desktop
For a complete API reference and advanced configuration options, check the Traefik documentation.

Clean Up

When you’re done experimenting, stop and remove the containers:
docker compose down

Build docs developers (and LLMs) love