Skip to content

Commit 20fe45e

Browse files
[feat] improve docker file
1 parent bde21e2 commit 20fe45e

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

content/guides/angular/containerize.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ description: Learn how to containerize an Angular application with Docker by cre
77

88
---
99

10-
1110
## Prerequisites
1211

1312
Before you begin, make sure the following tools are installed and available on your system:
@@ -124,6 +123,9 @@ Copy and replace the contents of your existing `Dockerfile` with the configurati
124123
# =========================================
125124
# Stage 1: Build the Angular Application
126125
# =========================================
126+
# =========================================
127+
# Stage 1: Build the Angular Application
128+
# =========================================
127129
ARG NODE_VERSION=22.14.0-alpine
128130
ARG NGINX_VERSION=alpine3.21
129131

@@ -134,16 +136,16 @@ FROM node:${NODE_VERSION} AS builder
134136
WORKDIR /app
135137

136138
# Copy package-related files first to leverage Docker's caching mechanism
137-
COPY --link package.json package-lock.json ./
139+
COPY package.json package-lock.json ./
138140

139141
# Install project dependencies using npm ci (ensures a clean, reproducible install)
140142
RUN --mount=type=cache,target=/root/.npm npm ci
141143

142144
# Copy the rest of the application source code into the container
143-
COPY --link . .
145+
COPY . .
144146

145-
# Build the Angular application (outputs to /app/dist)
146-
RUN npm run build
147+
# Build the Angular application
148+
RUN npm run build
147149

148150
# =========================================
149151
# Stage 2: Prepare Nginx to Serve Static Files
@@ -155,13 +157,10 @@ FROM nginxinc/nginx-unprivileged:${NGINX_VERSION} AS runner
155157
USER nginx
156158

157159
# Copy custom Nginx config
158-
COPY --link nginx.conf /etc/nginx/nginx.conf
159-
160-
# Application name
161-
ARG APP_NAME=docker-angular-sample
160+
COPY nginx.conf /etc/nginx/nginx.conf
162161

163162
# Copy the static build output from the build stage to Nginx's default HTML serving directory
164-
COPY --chown=nginx:root --link --from=builder /app/dist/${APP_NAME}/browser /usr/share/nginx/html
163+
COPY --chown=nginx:root --from=builder /app/dist/*/browser /usr/share/nginx/html
165164

166165
# Expose port 8080 to allow HTTP traffic
167166
# Note: The default NGINX container now listens on port 8080 instead of 80
@@ -170,6 +169,7 @@ EXPOSE 8080
170169
# Start Nginx directly with custom config
171170
ENTRYPOINT ["nginx", "-c", "/etc/nginx/nginx.conf"]
172171
CMD ["-g", "daemon off;"]
172+
173173
```
174174

175175
> [!NOTE]

0 commit comments

Comments
 (0)