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
[feat] update reactjs sample guide to use dhi example (#23821)
## Description
This PR adds a DHI-based Dockerfile example demonstrating how to build
an React.js application using the dhi-node image and serve it through
the dhi-nginx image.
## Reviews
- [x] Technical review
| What application platform does your project use? | Node |
81
-
| What version of Node do you want to use? | 24.7.0-alpine |
81
+
| What version of Node do you want to use? | 24.12.0-alpine |
82
82
| Which package manager do you want to use? | npm |
83
83
| Do you want to run "npm run build" before starting server? | yes |
84
84
| What directory is your build output to? | dist |
@@ -118,13 +118,93 @@ These updates help ensure your app is easy to deploy, fast to load, and producti
118
118
119
119
### Step 2: Configure the Dockerfile file
120
120
121
-
Copy and replace the contents of your existing `Dockerfile` with the configuration below:
121
+
Before creating a Dockerfile, you need to choose a base image. You can either use the [Node.js Official Image](https://hub.docker.com/_/node) or a Docker Hardened Image (DHI) from the [Hardened Image catalog](https://hub.docker.com/hardened-images/catalog).
122
+
123
+
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/).
124
+
125
+
> [!IMPORTANT]
126
+
> This guide uses a stable Node.js LTS image tag that is considered secure when the guide is written. Because new releases and security patches are published regularly, the tag shown here may no longer be the safest option when you follow the guide. Always review the latest available image tags and select a secure, up-to-date version before building or deploying your application.
127
+
>
128
+
> Official Node.js Docker Images: https://hub.docker.com/_/node
129
+
130
+
{{< tabs >}}
131
+
{{< tab name="Using Docker Hardened Images" >}}
132
+
Docker Hardened Images (DHIs) are available for Node.js in the [Docker Hardened Images catalog](https://hub.docker.com/hardened-images/catalog/dhi/node). Docker Hardened Images are freely available to everyone with no subscription required. You can pull and use them like any other Docker image after signing in to the DHI registry. For more information, see the [DHI quickstart](/dhi/get-started/) guide.
133
+
134
+
1. Sign in to the DHI registry:
135
+
```console
136
+
$ docker login dhi.io
137
+
```
138
+
139
+
2. Pull the Node.js DHI (check the catalog for available versions):
140
+
```console
141
+
$ docker pull dhi.io/node:24-alpine3.22-dev
142
+
```
143
+
144
+
3. Pull the Nginx DHI (check the catalog for available versions):
145
+
```console
146
+
$ docker pull dhi.io/nginx:1.28.0-alpine3.21-dev
147
+
```
148
+
149
+
In the following Dockerfile, the `FROM` instructions use `dhi.io/node:24-alpine3.22-dev` and `dhi.io/nginx:1.28.0-alpine3.21-dev` as the base images.
150
+
151
+
```dockerfile
152
+
# =========================================
153
+
# Stage 1: Build the React.js Application
154
+
# =========================================
155
+
156
+
# Use a lightweight Node.js image for building (customizable via ARG)
157
+
FROM dhi.io/node:24-alpine3.22-dev AS builder
158
+
159
+
# Set the working directory inside the container
160
+
WORKDIR /app
161
+
162
+
# Copy package-related files first to leverage Docker's caching mechanism
163
+
COPY package.json package-lock.json* ./
164
+
165
+
# Install project dependencies using npm ci (ensures a clean, reproducible install)
166
+
RUN --mount=type=cache,target=/root/.npm npm ci
167
+
168
+
# Copy the rest of the application source code into the container
169
+
COPY . .
170
+
171
+
# Build the React.js application (outputs to /app/dist)
172
+
RUN npm run build
173
+
174
+
# =========================================
175
+
# Stage 2: Prepare Nginx to Serve Static Files
176
+
# =========================================
177
+
178
+
FROM dhi.io/nginx:1.28.0-alpine3.21-dev AS runner
179
+
180
+
# Copy custom Nginx config
181
+
COPY nginx.conf /etc/nginx/nginx.conf
182
+
183
+
# Copy the static build output from the build stage to Nginx's default HTML serving directory
0 commit comments