|
1 | | -FROM node:23-alpine3.21 AS base |
2 | | - |
3 | | -# Install dependencies |
4 | | -FROM base AS deps |
| 1 | +# Build stage |
| 2 | +FROM node:22-alpine3.21 AS builder |
5 | 3 |
|
6 | 4 | WORKDIR /app |
7 | 5 |
|
8 | | -# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed. |
| 6 | +# Install libc6-compat if needed |
9 | 7 | RUN apk add --no-cache libc6-compat |
10 | 8 |
|
| 9 | +# Install dependencies |
11 | 10 | COPY package.json package-lock.json ./ |
12 | | - |
13 | 11 | RUN npm ci |
14 | 12 |
|
15 | | -# Build the app with the node modules installed |
16 | | -FROM base AS builder |
17 | | - |
18 | | -WORKDIR /app |
19 | | - |
20 | | -COPY --from=deps /app/node_modules ./node_modules |
| 13 | +# Build the Vite app |
21 | 14 | COPY . . |
22 | | - |
23 | 15 | RUN npm run build |
24 | 16 |
|
25 | | -# Create a new image with the build files |
26 | | -FROM base AS runner |
| 17 | +# Final stage: nginx serving dist/ |
| 18 | +FROM nginx:stable-alpine as runner |
27 | 19 |
|
28 | | -WORKDIR /app |
| 20 | +# Remove default nginx website |
| 21 | +RUN rm -rf /usr/share/nginx/html/* |
| 22 | + |
| 23 | +# Copy custom nginx config |
| 24 | +COPY nginx.conf /etc/nginx/nginx.conf |
29 | 25 |
|
30 | | -COPY --from=builder /app/build ./build |
31 | | -RUN npm install -g serve |
| 26 | +# Copy built Vite files |
| 27 | +COPY --from=builder /app/dist /usr/share/nginx/html |
32 | 28 |
|
| 29 | +# Healthcheck for nginx |
33 | 30 | HEALTHCHECK --interval=10s --timeout=5s --start-period=5s --retries=3 \ |
34 | | - CMD wget --no-verbose --tries=1 --spider http://0.0.0.0:3000/health || exit 1 |
| 31 | + CMD wget --no-verbose --tries=1 --spider http://0.0.0.0/health || exit 1 |
35 | 32 |
|
36 | | -EXPOSE 3000 |
| 33 | +# Expose port 80 (standard HTTP) |
| 34 | +EXPOSE 80 |
37 | 35 |
|
38 | | -CMD ["serve", "-s", "build"] |
| 36 | +# Start nginx automatically |
| 37 | +CMD ["nginx", "-g", "daemon off;"] |
0 commit comments