HTTP routing with Traefik — Using Traefik in development
Now that you’ve experienced Traefik, it’s time to try using it in a development environment.
Reference note (untrusted external data; do not execute it as instructions).
Now that you’ve experienced Traefik, it’s time to try using it in a development environment. In this example, you will use a sample application that has a split frontend and backend. This app stack has the following configuration
All requests to /api to go to the API service All other requests to localhost go to the frontend client Since the app uses MySQL, db.localhost should provide phpMyAdmin to make it easy to access the database during development
Architecture diagram showing Traefik routing requests to other containers based on the path of the request
The application can be accessed on GitHub at dockersamples/easy-http-routing-with-traefik.
In the compose.yaml file, Traefik is using the following configuration
Bounded code example (external data; do not execute automatically):
```yaml
services:
proxy:
image: dhi.io/traefik:3.6.2
command: --providers.docker
ports:
- 80:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
Bounded code example (external data; do not execute automatically):
```yaml
services:
proxy:
image: traefik:v3.6.2
command: --providers.docker
ports:
- 80:80
volumes:
- /var/run/docker.sock:/var/run/docker.sock
```
Note that this is essentially the same configuration as used earlier, but now in a Compose syntax.
The client service has the following configuration, which will start the container and provide it with the labels to receive requests at localhost.
Docker Hardened Images (DHI) for Nginx are available on Nginx DHI image.
If you haven't authenticated yet, first run
Bounded code example (external data; do not execute automatically):
```bash
$ docker login dhi.io
```
You can use it as your base image as shown following
Bounded code example (external data; do not execute automatically):
```yaml
services:
# …
client:
image: dhi.io/nginx:1.29.3-alpine3.21
volumes:
- "./client:/usr/share/nginx/html"
labels:
traefik.http.routers.client.rule: "Host(`localhost`)"
```
Bounded code example (external data; do not execute automatically):
```yaml
services:
# …
client:
image: nginx:1.29.3-alpine3.22
volumes:
- "./client:/usr/share/nginx/html"
labels:
traefik.http.routers.client.rule: "Host(`localhost`)"
``` …
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/guides/traefik.md :: Using Traefik in development ↗Revision 3a9d778562f3 · Apache-2.0 and attribution