Skip to content

Commit e21ee9d

Browse files
docs: Update Deno guide to include Docker Hardened Images (#23665)
<!--Delete sections as needed --> ## Description Add a section in the Deno guide to use DHI ## Reviews <!-- Notes for reviewers here --> <!-- List applicable reviews (optionally @tag reviewers) --> - [ ] Technical review - [x] Editorial review - [ ] Product review --------- Co-authored-by: Craig Osterhout <[email protected]>
1 parent 7759777 commit e21ee9d

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

content/guides/deno/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ params:
1010
time: 10 minutes
1111
---
1212

13-
The Deno getting started guide teaches you how to create a containerized Deno application using Docker. In this guide, you'll learn how to:
13+
The Deno getting started guide teaches you how to create a containerized Deno application using Docker.
1414

1515
> **Acknowledgment**
1616
>

content/guides/deno/containerize.md

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,42 @@ await app.listen({ port: 8000 });
6565

6666
## Create a Dockerfile
6767

68-
In the Dockerfile, you'll notice that the `FROM` instruction uses `denoland/deno:latest`
69-
as the base image. This is the official image for Deno. This image is [available on the Docker Hub](https://hub.docker.com/r/denoland/deno).
68+
Before creating a Dockerfile, you need to choose a base image. You can either use the [Deno Docker Official Image](https://hub.docker.com/r/denoland/deno) or a Docker Hardened Image (DHI) from the [Hardened Image catalog](https://hub.docker.com/hardened-images/catalog).
69+
70+
Choosing DHI offers the advantage of a production-ready image that is lightweight and secure. For more information, see [Docker Hardened Images](https://docs.docker.com/dhi/).
71+
72+
{{< tabs >}}
73+
{{< tab name="Using Docker Hardened Images" >}}
74+
Docker Hardened Images (DHIs) are available for Deno on [Docker Hub](https://hub.docker.com/hardened-images/catalog/dhi/deno). Unlike using the Docker Official Image, you must first mirror the Deno image into your organization and then use it as your base image. Follow the instructions in the [DHI quickstart](/dhi/get-started/) to create a mirrored repository for Deno.
75+
76+
Mirrored repositories must start with `dhi-`, for example: `FROM <your-namespace>/dhi-deno:<tag>`. In the following Dockerfile, the `FROM` instruction uses `<your-namespace>/dhi-deno:2` as the base image.
77+
78+
```dockerfile
79+
# Use the DHI Deno image as the base image
80+
FROM <your-namespace>/dhi-deno:2
81+
82+
# Set the working directory
83+
WORKDIR /app
84+
85+
# Copy server code into the container
86+
COPY server.ts .
87+
88+
# Set permissions (optional but recommended for security)
89+
USER deno
90+
91+
# Expose port 8000
92+
EXPOSE 8000
93+
94+
# Run the Deno server
95+
CMD ["run", "--allow-net", "server.ts"]
96+
```
97+
98+
{{< /tab >}}
99+
{{< tab name="Using the official image" >}}
100+
101+
Using the Docker Official Image is straightforward. In the following Dockerfile, you'll notice that the `FROM` instruction uses `denoland/deno:latest` as the base image.
102+
103+
This is the official image for Deno. This image is [available on the Docker Hub](https://hub.docker.com/r/denoland/deno).
70104

71105
```dockerfile
72106
# Use the official Deno image
@@ -88,7 +122,10 @@ EXPOSE 8000
88122
CMD ["run", "--allow-net", "server.ts"]
89123
```
90124

91-
Aside from specifying `denoland/deno:latest` as the base image, the Dockerfile:
125+
{{< /tab >}}
126+
{{< /tabs >}}
127+
128+
In addition to specifying the base image, the Dockerfile also:
92129

93130
- Sets the working directory in the container to `/app`.
94131
- Copies `server.ts` into the container.
@@ -139,6 +176,7 @@ Related information:
139176
- [.dockerignore file](/reference/dockerfile.md#dockerignore-file)
140177
- [Docker Compose overview](/manuals/compose/_index.md)
141178
- [Compose file reference](/reference/compose-file/_index.md)
179+
- [Docker Hardened Images](/dhi/)
142180

143181
## Next steps
144182

0 commit comments

Comments
 (0)