Skip to content

Commit 7e2af24

Browse files
authored
HTTP routing with Traefik: Update guide to include DHI (#23769)
<!--Delete sections as needed --> ## Description <!-- Tell us what you did and why --> ## Related issues or tickets <!-- Related issues, pull requests, or Jira tickets --> ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [x] Editorial review - [ ] Product review --------- Signed-off-by: MohammadHasan Akbari <jarqvi.jarqvi@gmail.com>
1 parent af235d1 commit 7e2af24

1 file changed

Lines changed: 153 additions & 18 deletions

File tree

content/guides/traefik.md

Lines changed: 153 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,78 @@ Let’s do a quick demo of starting Traefik and then configuring two additional
4747
$ docker network create traefik-demo
4848
```
4949

50-
2. Start a Traefik container using the following command. The command exposes Traefik on port 80, mounts the Docker socket (which is used to monitor containers to update configuration), and passes the `--providers.docker` argument to configure Traefik to use the Docker provider.
50+
2. Start a Traefik container using one of the following methods. These commands exposes Traefik on port 80, mounts the Docker socket (which is used to monitor containers to update configuration), and passes the `--providers.docker` argument to configure Traefik to use the Docker provider.
51+
52+
{{< tabs >}}
53+
{{< tab name="Using Docker Hardened Images" >}}
54+
55+
Docker Hardened Images (DHI) for Traefik are available on [Docker Hub](https://hub.docker.com/hardened-images/catalog/dhi/traefik).
56+
If you haven't authenticated yet, first run:
57+
58+
```bash
59+
$ docker login dhi.io
60+
```
61+
62+
Then start a container using the Hardened image:
63+
64+
```console
65+
$ docker run -d --network=traefik-demo \
66+
-p 80:80 \
67+
-v /var/run/docker.sock:/var/run/docker.sock \
68+
dhi.io/traefik:3.6.2 \
69+
--providers.docker
70+
```
71+
72+
{{< /tab >}}
73+
74+
{{< tab name="Using the official image" >}}
75+
76+
You can also use the official image from Docker Hub:
5177

5278
```console
53-
$ docker run -d --network=traefik-demo -p 80:80 -v /var/run/docker.sock:/var/run/docker.sock traefik:v3.6.2 --providers.docker
79+
$ docker run -d --network=traefik-demo \
80+
-p 80:80 \
81+
-v /var/run/docker.sock:/var/run/docker.sock \
82+
traefik:v3.6.2 \
83+
--providers.docker
5484
```
5585

86+
{{< /tab >}}
87+
{{< /tabs >}}
88+
5689
3. Now, start a simple Nginx container and define the labels Traefik is watching for to configure the HTTP routing. Note that the Nginx container is not exposing any ports.
5790

91+
{{< tabs >}}
92+
{{< tab name="Using Docker Hardened Images" >}}
93+
94+
Docker Hardened Images (DHI) for Nginx are available on [Nginx DHI image](https://hub.docker.com/hardened-images/catalog/dhi/nginx).
95+
If you haven't authenticated yet, first run:
96+
97+
```bash
98+
$ docker login dhi.io
99+
```
100+
58101
```console
59-
$ docker run -d --network=traefik-demo --label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' nginx
102+
$ docker run -d --network=traefik-demo \
103+
--label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' \
104+
dhi.io/nginx:1.29.3
60105
```
61106

107+
{{< /tab >}}
108+
109+
{{< tab name="Using the official image" >}}
110+
111+
You can also run the official Nginx image as follows:
112+
113+
```console
114+
$ docker run -d --network=traefik-demo \
115+
--label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' \
116+
nginx:1.29.3
117+
```
118+
119+
{{< /tab >}}
120+
{{< /tabs >}}
121+
62122
Once the container starts, open your browser to [http://nginx.localhost](http://nginx.localhost) to see the app (all Chromium-based browsers route \*.localhost requests locally with no additional setup).
63123

64124
4. Start a second application that will use a different hostname.
@@ -83,6 +143,24 @@ The application can be accessed on GitHub at [dockersamples/easy-http-routing-wi
83143

84144
1. In the `compose.yaml` file, Traefik is using the following configuration:
85145

146+
{{< tabs >}}
147+
{{< tab name="Using DHI image" >}}
148+
149+
```yaml
150+
services:
151+
proxy:
152+
image: dhi.io/traefik:3.6.2
153+
command: --providers.docker
154+
ports:
155+
- 80:80
156+
volumes:
157+
- /var/run/docker.sock:/var/run/docker.sock
158+
```
159+
160+
{{< /tab >}}
161+
162+
{{< tab name="Using official image" >}}
163+
86164
```yaml
87165
services:
88166
proxy:
@@ -94,21 +172,55 @@ The application can be accessed on GitHub at [dockersamples/easy-http-routing-wi
94172
- /var/run/docker.sock:/var/run/docker.sock
95173
```
96174
175+
{{< /tab >}}
176+
{{< /tabs >}}
177+
97178
Note that this is essentially the same configuration as used earlier, but now in a Compose syntax.
98179
99180
2. The client service has the following configuration, which will start the container and provide it with the labels to receive requests at localhost.
100181
101-
```yaml {hl_lines=[7,8]}
182+
{{< tabs >}}
183+
{{< tab name="Using Docker Hardened Images" >}}
184+
185+
Docker Hardened Images (DHI) for Nginx are available on [Nginx DHI image](https://hub.docker.com/hardened-images/catalog/dhi/nginx).
186+
187+
If you haven't authenticated yet, first run:
188+
189+
```bash
190+
$ docker login dhi.io
191+
```
192+
193+
You can use it as your base image as shown following:
194+
195+
```yaml
102196
services:
103197
#
104198
client:
105-
image: nginx:alpine
199+
image: dhi.io/nginx:1.29.3-alpine3.21
106200
volumes:
107201
- "./client:/usr/share/nginx/html"
108202
labels:
109203
traefik.http.routers.client.rule: "Host(`localhost`)"
110204
```
111205
206+
{{< /tab >}}
207+
208+
{{< tab name="Using the official image" >}}
209+
210+
```yaml
211+
services:
212+
#
213+
client:
214+
image: nginx:1.29.3-alpine3.22
215+
volumes:
216+
- "./client:/usr/share/nginx/html"
217+
labels:
218+
traefik.http.routers.client.rule: "Host(`localhost`)"
219+
```
220+
221+
{{< /tab >}}
222+
{{< /tabs >}}
223+
112224
3. The api service has a similar configuration, but you’ll notice the routing rule has two conditions - the host must be “localhost” and the URL path must have a prefix of “/api”. Since this rule is more specific, Traefik will evaluate it first compared to the client rule.
113225
114226
```yaml {hl_lines=[7,8]}
@@ -138,7 +250,7 @@ The application can be accessed on GitHub at [dockersamples/easy-http-routing-wi
138250
139251
5. Before starting the stack, stop the Nginx container if it is still running.
140252
141-
And that’s it. Now, you only need to spin up the Compose stack with a `docker compose up` and all of the services and applications will be ready for development.
253+
And that’s it. Now, you only need to spin up the Compose stack with a `docker compose up` and all of the services and applications will be ready for development.
142254

143255
## Sending traffic to non-containerized workloads
144256

@@ -176,18 +288,41 @@ With this file, the only change is to the Compose configuration for Traefik. The
176288
1. The configuration file is mounted into the Traefik container (the exact destination path is up to you)
177289
2. The `command` is updated to add the file provider and point to the location of the configuration file
178290

179-
```yaml
180-
services:
181-
proxy:
182-
image: traefik:v3.6.2
183-
command: --providers.docker --providers.file.filename=/config/traefik-config.yaml --api.insecure
184-
ports:
185-
- 80:80
186-
- 8080:8080
187-
volumes:
188-
- /var/run/docker.sock:/var/run/docker.sock
189-
- ./dev/traefik-config.yaml:/config/traefik-config.yaml
190-
```
291+
{{< tabs >}}
292+
{{< tab name="Using DHI image" >}}
293+
294+
```yaml
295+
services:
296+
proxy:
297+
image: dhi.io/traefik:3.6.2
298+
command: --providers.docker --providers.file.filename=/config/traefik-config.yaml --api.insecure
299+
ports:
300+
- 80:80
301+
- 8080:8080
302+
volumes:
303+
- /var/run/docker.sock:/var/run/docker.sock
304+
- ./dev/traefik-config.yaml:/config/traefik-config.yaml
305+
```
306+
307+
{{< /tab >}}
308+
309+
{{< tab name="Using official image" >}}
310+
311+
```yaml
312+
services:
313+
proxy:
314+
image: traefik:v3.6.2
315+
command: --providers.docker --providers.file.filename=/config/traefik-config.yaml --api.insecure
316+
ports:
317+
- 80:80
318+
- 8080:8080
319+
volumes:
320+
- /var/run/docker.sock:/var/run/docker.sock
321+
- ./dev/traefik-config.yaml:/config/traefik-config.yaml
322+
```
323+
324+
{{< /tab >}}
325+
{{< /tabs >}}
191326

192327
### Starting the example app
193328

0 commit comments

Comments
 (0)