2022-04-15 16:44:08 +03:00
---
title: "Traefik Getting Started Quickly"
2024-01-02 19:30:06 +03:00
description: "Get started with Traefik Proxy and Docker."
2022-04-15 16:44:08 +03:00
---
2019-02-26 16:50:07 +03:00
# Quick Start
2024-01-02 19:30:06 +03:00
A Use Case Using Docker
2019-02-26 16:50:07 +03:00
{: .subtitle }
![quickstart-diagram ](../assets/img/quickstart-diagram.png )
## Launch Traefik With the Docker Provider
Create a `docker-compose.yml` file where you will define a `reverse-proxy` service that uses the official Traefik image:
```yaml
version: '3'
services:
reverse-proxy:
2020-02-17 13:04:04 +03:00
# The official v2 Traefik docker image
2024-01-03 13:12:05 +03:00
image: traefik:v2.11
2019-07-01 12:30:05 +03:00
# Enables the web UI and tells Traefik to listen to docker
2019-09-12 17:22:03 +03:00
command: --api.insecure=true --providers.docker
2019-02-26 16:50:07 +03:00
ports:
2019-07-01 12:30:05 +03:00
# The HTTP port
- "80:80"
2019-09-12 17:22:03 +03:00
# The Web UI (enabled by --api.insecure=true)
2019-07-01 12:30:05 +03:00
- "8080:8080"
2019-02-26 16:50:07 +03:00
volumes:
2019-07-01 12:30:05 +03:00
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
2019-02-26 16:50:07 +03:00
```
**That's it. Now you can launch Traefik!**
Start your `reverse-proxy` with the following command:
```shell
docker-compose up -d reverse-proxy
```
2024-01-02 19:30:06 +03:00
You can open a browser and go to `http://localhost:8080/api/rawdata` to see Traefik's API rawdata (you'll go back there once you have launched a service in step 2).
2019-02-26 16:50:07 +03:00
## Traefik Detects New Services and Creates the Route for You
2024-01-02 19:30:06 +03:00
Now that you have a Traefik instance up and running, you will deploy new services.
2019-02-26 16:50:07 +03:00
Edit your `docker-compose.yml` file and add the following at the end of your file.
```yaml
2022-11-30 17:04:05 +03:00
version: '3'
services:
...
2019-02-26 16:50:07 +03:00
whoami:
2019-07-01 12:30:05 +03:00
# A container that exposes an API to show its IP address
2020-09-16 16:46:04 +03:00
image: traefik/whoami
2019-02-26 16:50:07 +03:00
labels:
2019-03-21 17:34:04 +03:00
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
2019-02-26 16:50:07 +03:00
```
2024-01-02 19:30:06 +03:00
The above defines `whoami` : a web service that outputs information about the machine it is deployed on (its IP address, host, and others).
2019-02-26 16:50:07 +03:00
Start the `whoami` service with the following command:
```shell
docker-compose up -d whoami
```
2021-10-08 12:52:05 +03:00
Go back to your browser (`http://localhost:8080/api/rawdata`) and see that Traefik has automatically detected the new container and updated its own configuration.
2019-02-26 16:50:07 +03:00
2024-01-02 19:30:06 +03:00
When Traefik detects new services, it creates the corresponding routes so you can call them ... _let's see!_ (Here, you're using curl)
2019-02-26 16:50:07 +03:00
```shell
curl -H Host:whoami.docker.localhost http://127.0.0.1
```
_Shows the following output:_
```yaml
Hostname: a656c8ddca6c
IP: 172.27.0.3
#...
```
## More Instances? Traefik Load Balances Them
Run more instances of your `whoami` service with the following command:
```shell
docker-compose up -d --scale whoami=2
```
2021-10-08 12:52:05 +03:00
Go back to your browser (`http://localhost:8080/api/rawdata`) and see that Traefik has automatically detected the new instance of the container.
2019-02-26 16:50:07 +03:00
2019-05-17 14:32:05 +03:00
Finally, see that Traefik load-balances between the two instances of your service by running the following command twice:
2019-02-26 16:50:07 +03:00
```shell
curl -H Host:whoami.docker.localhost http://127.0.0.1
```
2024-01-02 19:30:06 +03:00
The output will show alternatively one of the following:
2019-02-26 16:50:07 +03:00
```yaml
Hostname: a656c8ddca6c
IP: 172.27.0.3
#...
```
```yaml
Hostname: s458f154e1f1
IP: 172.27.0.4
# ...
```
!!! question "Where to Go Next?"
2022-07-05 11:02:09 +03:00
2024-06-06 16:46:03 +03:00
Now that you have a basic understanding of how Traefik can automatically create the routes to your services and load balance them, it is time to dive into [the user guides ](../../user-guides/docker-compose/basic-example/ "Link to the user guides" ) and [the documentation ](/ "Link to the docs landing page" ) and let Traefik work for you!
2022-07-05 11:02:09 +03:00
2022-09-09 18:17:53 +03:00
{!traefik-for-business-applications.md!}