docs/content/getting-started/docker.md
Docker is a first-class citizen in Traefik, offering native support for Docker containers and services. Whether you're using Docker Compose or running containers directly, Traefik provides a seamless experience for managing your Docker traffic.
This guide shows you how to:
Create a Docker Compose file. This configuration:
--api.insecure=true (development use only)# docker-compose.yml
services:
traefik:
image: traefik:v3.7
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--entrypoints.web.address=:80"
ports:
- "80:80"
- "8080:8080"
volumes:
- /var/run/docker.sock:/var/run/docker.sock
Start Traefik:
docker-compose up -d
Alternatively, you can run Traefik directly with Docker. This command:
Create a configuration file:
# traefik.yml
api:
insecure: true
entryPoints:
web:
address: ":80"
providers:
docker: {}
Start Traefik:
docker run -d \
-p 80:80 \
-p 8080:8080 \
-v $PWD/traefik.yml:/etc/traefik/traefik.yml \
-v /var/run/docker.sock:/var/run/docker.sock \
traefik:v3.7
Because we explicitly enabled insecure mode, the dashboard is reachable on port 8080 without authentication. Do not enable this flag in production.
You can access the dashboard at:
http://localhost:8080/dashboard/
Create a whoami service:
# whoami.yml
services:
whoami:
image: traefik/whoami
labels:
- "traefik.http.routers.whoami.rule=Host(`whoami.localhost`)"
Apply the configuration:
docker-compose -f whoami.yml up -d
You can use the following curl command to verify that the application is correctly exposed:
curl http://whoami.localhost
Hostname: 068c0a29a8b7
IP: 127.0.0.1
IP: ::1
IP: 192.168.147.3
RemoteAddr: 192.168.147.2:56006
GET / HTTP/1.1
Host: whoami.localhost
User-Agent: curl/8.7.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 192.168.147.1
X-Forwarded-Host: whoami.localhost
X-Forwarded-Port: 80
X-Forwarded-Proto: http
X-Forwarded-Server: 9232cdd4fd6c
X-Real-Ip: 192.168.147.1
You can also open http://whoami.localhost in a browser to test the application:
If you navigate to the HTTP Routers section of the Traefik dashboard, you can see that the whoami.localhost route is managed by the Traefik Docker provider:
That's it! You've successfully deployed Traefik and configured routing in Docker.
{% include-markdown "includes/traefik-for-business-applications.md" %}