-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (27 loc) · 1.08 KB
/
Dockerfile
File metadata and controls
40 lines (27 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
ARG NODE_VERSION=22
FROM node:${NODE_VERSION}-alpine AS build
ARG NPM_VERSION=11.11.0
WORKDIR /app
# Install specific NPM version via curl/npm before installing dependencies
RUN npm install -g npm@${NPM_VERSION}
# Copy dependency files first to leverage Docker layer caching
COPY package*.json ./
# Use 'npm ci' for faster, more reliable builds in CI/CD environments
RUN npm ci
# Copy the rest of the source code
COPY . .
# Generate the static assets (dist folder)
RUN npm run build
# Remove development dependencies to keep the build stage clean
RUN npm prune --production
# Stage 2: Production environment
FROM nginx:1.29.3-alpine3.22-slim AS production
# Clean default static files
RUN rm -rf /usr/share/nginx/html/*
# Copy only the compiled assets from the build stage
# Note: Ensure your framework outputs to /app/dist (standard for Vite/Vue/React)
COPY --from=build /app/dist /usr/share/nginx/html
# Update Nginx to listen on 8080 (standard for non-root/containerized environments)
RUN sed -i 's/listen\s\+80;/listen 8080;/' /etc/nginx/conf.d/default.conf
# Expose the new port
EXPOSE 8080