Skip to content

Commit 3c446a7

Browse files
committed
chore: use dhi in traefik guide
1 parent a406224 commit 3c446a7

File tree

1 file changed

+147
-27
lines changed

1 file changed

+147
-27
lines changed

content/guides/traefik.md

Lines changed: 147 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,71 @@ 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.
5151

52-
```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
54-
```
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+
Before you can use a DHI image, you must mirror it into your organization’s namespace.
57+
Follow the [DHI quickstart](/dhi/get-started/) to create a mirrored repository.
58+
59+
For example — use:
60+
`FROM <your-namespace>/dhi-traefik:<tag>`
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+
<your-namespace>/dhi-traefik:3.6.2 \
69+
--providers.docker
70+
```
71+
72+
{{< /tab >}}
73+
{{< tab name="Using the official image" >}}
74+
75+
You can also use the official image from Docker Hub:
76+
77+
```console
78+
$ docker run -d --network=traefik-demo \
79+
-p 80:80 \
80+
-v /var/run/docker.sock:/var/run/docker.sock \
81+
traefik:v3.6.2 \
82+
--providers.docker
83+
```
84+
85+
{{< /tab >}}
86+
{{< /tabs >}}
5587

5688
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.
5789

58-
```console
59-
$ docker run -d --network=traefik-demo --label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' nginx
60-
```
90+
{{< tabs >}}
91+
{{< tab name="Using Docker Hardened Images" >}}
92+
93+
If your organization uses an [Nginx DHI image](https://hub.docker.com/hardened-images/catalog/dhi/nginx),
94+
you can use the mirrored image name below. For example:
95+
96+
```console
97+
$ docker run -d --network=traefik-demo \
98+
--label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' \
99+
<your-namespace>/dhi-nginx:1.29.3
100+
```
101+
102+
{{< /tab >}}
103+
{{< tab name="Using the official image" >}}
104+
105+
You can also run the official NGINX image as follows:
106+
107+
```console
108+
$ docker run -d --network=traefik-demo \
109+
--label 'traefik.http.routers.nginx.rule=Host(`nginx.localhost`)' \
110+
nginx:1.29.3
111+
```
112+
113+
{{< /tab >}}
114+
{{< /tabs >}}
61115

62116
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).
63117

@@ -83,31 +137,74 @@ The application can be accessed on GitHub at [dockersamples/easy-http-routing-wi
83137

84138
1. In the `compose.yaml` file, Traefik is using the following configuration:
85139

86-
```yaml
87-
services:
88-
proxy:
89-
image: traefik:v3.6.2
90-
command: --providers.docker
91-
ports:
92-
- 80:80
93-
volumes:
94-
- /var/run/docker.sock:/var/run/docker.sock
95-
```
140+
{{< tabs >}}
141+
{{< tab name="Using DHI image" >}}
142+
143+
```yaml
144+
services:
145+
proxy:
146+
image: <your-namespace>/dhi-traefik:3.6.2
147+
command: --providers.docker
148+
ports:
149+
- 80:80
150+
volumes:
151+
- /var/run/docker.sock:/var/run/docker.sock
152+
```
153+
154+
{{< /tab >}}
155+
{{< tab name="Using official image" >}}
156+
157+
```yaml
158+
services:
159+
proxy:
160+
image: traefik:v3.6.2
161+
command: --providers.docker
162+
ports:
163+
- 80:80
164+
volumes:
165+
- /var/run/docker.sock:/var/run/docker.sock
166+
```
167+
168+
{{< /tab >}}
169+
{{< /tabs >}}
96170
97171
Note that this is essentially the same configuration as used earlier, but now in a Compose syntax.
98172
99173
2. The client service has the following configuration, which will start the container and provide it with the labels to receive requests at localhost.
100174
101-
```yaml {hl_lines=[7,8]}
102-
services:
103-
#
104-
client:
105-
image: nginx:alpine
106-
volumes:
107-
- "./client:/usr/share/nginx/html"
108-
labels:
109-
traefik.http.routers.client.rule: "Host(`localhost`)"
110-
```
175+
{{< tabs >}}
176+
{{< tab name="Using Docker Hardened Images" >}}
177+
178+
If your organization mirrors the [Nginx DHI image](https://hub.docker.com/hardened-images/catalog/dhi/nginx),
179+
you can use it as your base image as shown below:
180+
181+
```yaml
182+
services:
183+
#
184+
client:
185+
image: <your-namespace>/dhi-nginx:1.29.3-alpine3.21
186+
volumes:
187+
- "./client:/usr/share/nginx/html"
188+
labels:
189+
traefik.http.routers.client.rule: "Host(`localhost`)"
190+
```
191+
192+
{{< /tab >}}
193+
{{< tab name="Using the official image" >}}
194+
195+
```yaml
196+
services:
197+
#
198+
client:
199+
image: nginx:1.29.3-alpine3.22
200+
volumes:
201+
- "./client:/usr/share/nginx/html"
202+
labels:
203+
traefik.http.routers.client.rule: "Host(`localhost`)"
204+
```
205+
206+
{{< /tab >}}
207+
{{< /tabs >}}
111208
112209
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.
113210
@@ -176,6 +273,26 @@ With this file, the only change is to the Compose configuration for Traefik. The
176273
1. The configuration file is mounted into the Traefik container (the exact destination path is up to you)
177274
2. The `command` is updated to add the file provider and point to the location of the configuration file
178275

276+
{{< tabs >}}
277+
{{< tab name="Using DHI image" >}}
278+
279+
```yaml
280+
services:
281+
proxy:
282+
image: <your-namespace>/dhi-traefik:3.6.2
283+
command: --providers.docker --providers.file.filename=/config/traefik-config.yaml --api.insecure
284+
ports:
285+
- 80:80
286+
- 8080:8080
287+
volumes:
288+
- /var/run/docker.sock:/var/run/docker.sock
289+
- ./dev/traefik-config.yaml:/config/traefik-config.yaml
290+
```
291+
292+
{{< /tab >}}
293+
294+
{{< tab name="Using official image" >}}
295+
179296
```yaml
180297
services:
181298
proxy:
@@ -189,6 +306,9 @@ services:
189306
- ./dev/traefik-config.yaml:/config/traefik-config.yaml
190307
```
191308

309+
{{< /tab >}}
310+
{{< /tabs >}}
311+
192312
### Starting the example app
193313

194314
To run the example app that forwards requests from Traefik to native-running apps, use the following steps:

0 commit comments

Comments
 (0)