- Scaffolded Angular 21 app in frontend/ (standalone, routing, scss) - Multi-stage Dockerfile: node:22-alpine build → nginx:alpine serve - nginx.conf with SPA routing fallback, API proxy, gzip, asset caching - .dockerignore excludes node_modules, dist, .angular, spec files - docker build → PASS, container serves UI on port 80 (HTTP 200) - Final image: 92.9MB (nginx:alpine)
28 lines
631 B
Docker
28 lines
631 B
Docker
# Stage 1: Build the Angular application
|
|
FROM node:22-alpine AS build
|
|
|
|
WORKDIR /app
|
|
|
|
# Copy package files first for better layer caching
|
|
COPY package.json package-lock.json ./
|
|
RUN npm ci
|
|
|
|
# Copy source and build
|
|
COPY . .
|
|
RUN npx ng build --configuration production
|
|
|
|
# Stage 2: Serve static files with nginx
|
|
FROM nginx:alpine
|
|
|
|
# Remove default nginx config
|
|
RUN rm /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy custom nginx config
|
|
COPY nginx.conf /etc/nginx/conf.d/default.conf
|
|
|
|
# Copy built Angular artifacts from build stage
|
|
COPY --from=build /app/dist/frontend/browser /usr/share/nginx/html
|
|
|
|
EXPOSE 80
|
|
|
|
CMD ["nginx", "-g", "daemon off;"] |