File size: 1,183 Bytes
1596e3f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
41
42
43
44
# -----------------------------------------------
# Multi-stage Dockerfile for a React + Vite PWA
# -----------------------------------------------

# 1) Build stage
FROM node:20-alpine AS build

WORKDIR /app

# Install global pnpm for faster installs
RUN corepack enable && corepack prepare pnpm@latest --activate

# Copy dependency manifests first for better layer caching
COPY package.json pnpm-lock.yaml ./

# Install all dependencies (including devDependencies for build)
RUN pnpm install --frozen-lockfile

# Copy source files
COPY . .

# Build the production bundle
RUN pnpm run build

# -----------------------------------------------
# 2) Runtime stage – tiny nginx image
# -----------------------------------------------
FROM nginx:1.25-alpine

# Copy built static assets from build stage
COPY --from=build /app/dist /usr/share/nginx/html

# Copy custom nginx config to serve SPA & PWA headers
COPY nginx.conf /etc/nginx/conf.d/default.conf

# Allow nginx to bind to privileged ports as non-root
RUN touch /var/run/nginx.pid && \
    chown -R nginx:nginx /var/run/nginx.pid /usr/share/nginx/html /var/cache/nginx

USER nginx

EXPOSE 80

CMD ["nginx", "-g", "daemon off;"]