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
| What application platform does your project use? | Node |
80
-
| What version of Node do you want to use? |23.11.0-alpine |
80
+
| What version of Node do you want to use? |24.11.1-alpine |
81
81
| Which package manager do you want to use? | npm |
82
82
| Do you want to run "npm run build" before starting server? | yes |
83
83
| What directory is your build output to? | dist |
@@ -114,19 +114,80 @@ These updates help ensure your app is easy to deploy, fast to load, and producti
114
114
> A `Dockerfile` is a plain text file that contains step-by-step instructions to build a Docker image. It automates packaging your application along with its dependencies and runtime environment.
115
115
> For full details, see the [Dockerfile reference](/reference/dockerfile/).
116
116
117
-
118
117
### Step 2: Configure the Dockerfile
119
118
120
-
Copy and replace the contents of your existing `Dockerfile` with the configuration below:
119
+
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).
120
+
121
+
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/).
122
+
123
+
> [!IMPORTANT]
124
+
> 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.
125
+
>
126
+
> Official Node.js Docker Images: https://hub.docker.com/_/node
127
+
128
+
{{< tabs >}}
129
+
{{< tab name="Using Docker Hardened Images" >}}
130
+
Docker Hardened Images (DHIs) are available for Node.js on [Docker Hub](https://hub.docker.com/hardened-images/catalog/dhi/node). Unlike using the Docker Official Image, you must first mirror the Node.js 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 Node.js.
131
+
132
+
Mirrored repositories must start with `dhi-`, for example: `FROM <your-namespace>/dhi-node:<tag>`. In the following Dockerfile, the `FROM` instruction uses `<your-namespace>/dhi-node:24-alpine3.22-dev` as the base image.
121
133
122
134
```dockerfile
123
135
# =========================================
124
136
# Stage 1: Build the Angular Application
125
137
# =========================================
138
+
139
+
# Use a lightweight Node.js image for building (customizable via ARG)
140
+
FROM <your-namespace>/dhi-node:24-alpine3.22-dev AS builder
141
+
142
+
# Set the working directory inside the container
143
+
WORKDIR /app
144
+
145
+
# Copy package-related files first to leverage Docker's caching mechanism
146
+
COPY package.json package-lock.json ./
147
+
148
+
# Install project dependencies using npm ci (ensures a clean, reproducible install)
149
+
RUN --mount=type=cache,target=/root/.npm npm ci
150
+
151
+
# Copy the rest of the application source code into the container
152
+
COPY . .
153
+
154
+
# Build the Angular application
155
+
RUN npm run build
156
+
157
+
# =========================================
158
+
# Stage 2: Prepare Nginx to Serve Static Files
159
+
# =========================================
160
+
161
+
FROM <your-namespace>/dhi-nginx:1.28.0-alpine3.21-dev AS runner
162
+
163
+
# Copy custom Nginx config
164
+
COPY nginx.conf /etc/nginx/nginx.conf
165
+
166
+
# Copy the static build output from the build stage to Nginx's default HTML serving directory
0 commit comments