traefik/docs/content/getting-started/quick-start.md

125 lines
3.4 KiB
Markdown
Raw Normal View History

---
title: "Traefik Getting Started Quickly"
2023-03-22 15:53:41 +00:00
description: "Looking to get started with Traefik Proxy quickly? Read the technical documentation to see a basic use case that leverages Docker."
---
# Quick Start
2023-03-22 15:53:41 +00:00
A Basic Use Case Using Docker
{: .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:
2023-03-22 15:53:41 +00:00
# The official v3 Traefik Docker image
2022-12-05 15:58:04 +00:00
image: traefik:v3.0
2023-03-22 15:53:41 +00:00
# Enables the web UI and tells Traefik to listen to Docker
command: --api.insecure=true --providers.docker
ports:
2019-07-01 09:30:05 +00:00
# The HTTP port
- "80:80"
# The Web UI (enabled by --api.insecure=true)
2019-07-01 09:30:05 +00:00
- "8080:8080"
volumes:
2019-07-01 09:30:05 +00:00
# So that Traefik can listen to the Docker events
- /var/run/docker.sock:/var/run/docker.sock
```
**That's it. Now you can launch Traefik!**
Start your `reverse-proxy` with the following command:
```shell
docker-compose up -d reverse-proxy
```
You can open a browser and go to `http://localhost:8080/api/rawdata` to see Traefik's API rawdata (we'll go back there once we have launched a service in step 2).
## Traefik Detects New Services and Creates the Route for You
Now that we have a Traefik instance up and running, we will deploy new services.
Edit your `docker-compose.yml` file and add the following at the end of your file.
```yaml
2022-11-30 14:04:05 +00:00
version: '3'
services:
...
whoami:
2019-07-01 09:30:05 +00:00
# A container that exposes an API to show its IP address
image: traefik/whoami
labels:
2019-03-21 14:34:04 +00:00
- "traefik.http.routers.whoami.rule=Host(`whoami.docker.localhost`)"
```
2023-03-22 15:53:41 +00:00
The above defines [`whoami`](https://github.com/traefik/whoami "Link to whoami app on GitHub"), a web service that outputs information about the machine it is deployed on (its IP address, host, etc.).
Start the `whoami` service with the following command:
```shell
docker-compose up -d whoami
```
2023-03-22 15:53:41 +00:00
Browse `http://localhost:8080/api/rawdata` and see that Traefik has automatically detected the new container and updated its own configuration.
2023-03-22 15:53:41 +00:00
When Traefik detects new services, it creates the corresponding routes, so you can call them ... _let's see!_ (Here, we're using curl)
```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
```
2023-03-22 15:53:41 +00:00
Browse to `http://localhost:8080/api/rawdata` and see that Traefik has automatically detected the new instance of the container.
2019-05-17 11:32:05 +00:00
Finally, see that Traefik load-balances between the two instances of your service by running the following command twice:
```shell
curl -H Host:whoami.docker.localhost http://127.0.0.1
```
The output will show alternatively one of the followings:
```yaml
Hostname: a656c8ddca6c
IP: 172.27.0.3
#...
```
```yaml
Hostname: s458f154e1f1
IP: 172.27.0.4
# ...
```
!!! question "Where to Go Next?"
2023-03-22 15:53:41 +00: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 documentation](/ "Link to the docs landing page") and let Traefik work for you!
2022-09-09 15:17:53 +00:00
{!traefik-for-business-applications.md!}