Skip to content

Commit c0e404f

Browse files
docs: Add a section in the Bun guide to use DHI (#23565)
<!--Delete sections as needed --> ## Description Add a section in the Bun 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: Usha Mandya <[email protected]>
1 parent 8956abd commit c0e404f

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

content/guides/bun/_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 Bun getting started guide teaches you how to create a containerized Bun application using Docker. In this guide, you'll learn how to:
13+
The Bun getting started guide teaches you how to create a containerized Bun application using Docker.
1414

1515
> **Acknowledgment**
1616
>

content/guides/bun/containerize.md

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,44 @@ You should now have the following contents in your `bun-docker` directory.
5050
│ └── README.md
5151
```
5252

53-
In the Dockerfile, you'll notice that the `FROM` instruction uses `oven/bun`
54-
as the base image. This is the official image for Bun created by Oven, the
55-
company behind Bun. This image is [available on the Docker Hub](https://hub.docker.com/r/oven/bun).
53+
## Create a Dockerfile
54+
55+
Before creating a Dockerfile, you need to choose a base image. You can either use the [Bun Docker Official Image](https://hub.docker.com/r/oven/bun) or a Docker Hardened Image (DHI) from the [Hardened Image catalog](https://hub.docker.com/hardened-images/catalog).
56+
57+
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/).
58+
59+
{{< tabs >}}
60+
{{< tab name="Using Docker Hardened Images" >}}
61+
Docker Hardened Images (DHIs) are available for Bun on [Docker Hub](https://hub.docker.com/hardened-images/catalog/dhi/bun). Unlike using the Docker Official Image, you must first mirror the Bun 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 Bun.
62+
63+
Mirrored repositories must start with `dhi-`, for example: `FROM <your-namespace>/dhi-bun:<tag>`. In the following Dockerfile, the `FROM` instruction uses `<your-namespace>/dhi-bun:1` as the base image.
5664

5765
```dockerfile
58-
# Use the Bun image as the base image
66+
# Use the DHI Bun image as the base image
67+
FROM <your-namespace>/dhi-bun:1
68+
69+
# Set the working directory in the container
70+
WORKDIR /app
71+
72+
# Copy the current directory contents into the container at /app
73+
COPY . .
74+
75+
# Expose the port on which the API will listen
76+
EXPOSE 3000
77+
78+
# Run the server when the container launches
79+
CMD ["bun", "server.js"]
80+
```
81+
82+
{{< /tab >}}
83+
{{< tab name="Using the official image" >}}
84+
85+
Using the Docker Official Image is straightforward. In the following Dockerfile, you'll notice that the `FROM` instruction uses `oven/bun` as the base image.
86+
87+
You can find the image on [Docker Hub](https://hub.docker.com/r/oven/bun). This is the Docker Official Image for Bun created by Oven, the company behind Bun, and it's available on Docker Hub.
88+
89+
```dockerfile
90+
# Use the official Bun image
5991
FROM oven/bun:latest
6092

6193
# Set the working directory in the container
@@ -71,11 +103,14 @@ EXPOSE 3000
71103
CMD ["bun", "server.js"]
72104
```
73105

74-
Aside from specifying `oven/bun` as the base image, this Dockerfile also:
106+
{{< /tab >}}
107+
{{< /tabs >}}
108+
109+
In addition to specifying the base image, the Dockerfile also:
75110

76-
- Sets the working directory in the container to `/app`
77-
- Copies the contents of the current directory to the `/app` directory in the container
78-
- Exposes port 3000, where the API is listening for requests
111+
- Sets the working directory in the container to `/app`.
112+
- Copies the content of the current directory to the `/app` directory in the container.
113+
- Exposes port 3000, where the API is listening for requests.
79114
- And finally, starts the server when the container launches with the command `bun server.js`.
80115

81116
## Run the application
@@ -120,6 +155,7 @@ Related information:
120155
- [.dockerignore file](/reference/dockerfile.md#dockerignore-file)
121156
- [Docker Compose overview](/manuals/compose/_index.md)
122157
- [Compose file reference](/reference/compose-file/_index.md)
158+
- [Docker Hardened Images](/dhi/)
123159

124160
## Next steps
125161

0 commit comments

Comments
 (0)