You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/guides/bun/containerize.md
+44-8Lines changed: 44 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,12 +50,44 @@ You should now have the following contents in your `bun-docker` directory.
50
50
│ └── README.md
51
51
```
52
52
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.
56
64
57
65
```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
59
91
FROM oven/bun:latest
60
92
61
93
# Set the working directory in the container
@@ -71,11 +103,14 @@ EXPOSE 3000
71
103
CMD ["bun", "server.js"]
72
104
```
73
105
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:
75
110
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.
79
114
- And finally, starts the server when the container launches with the command `bun server.js`.
0 commit comments