1- # syntax=docker/dockerfile:1
2-
3- # Comments are provided throughout this file to help you get started.
4- # If you need more help, visit the Dockerfile reference guide at
5- # https://docs.docker.com/go/dockerfile-reference/
6-
7- # Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7
8-
9- ARG NODE_VERSION=22.18.0
1+ ARG NODE_VERSION=24.11.0
102ARG PNPM_VERSION=10.32.1
113
12- # ###############################################################################
13- # Use node image for base image for all stages.
14- FROM node:${NODE_VERSION}-alpine as base
4+ # =================== base stage ============================================
5+ FROM node:${NODE_VERSION}-alpine AS base
156
16- # Set working directory for all build stages.
177WORKDIR /usr/src/app
188
19- # Install pnpm.
20- RUN --mount=type=cache,target=/root/.npm \
21- npm install -g pnpm@${PNPM_VERSION}
22-
23- # ###############################################################################
24- # Create a stage for installing production dependecies.
9+ # =================== deps stage ============================================
2510FROM base as deps
2611
27- # Download dependencies as a separate step to take advantage of Docker's caching.
28- # Leverage a cache mount to /root/.local/share/pnpm/store to speed up subsequent builds.
29- # Leverage bind mounts to package.json and pnpm-lock.yaml to avoid having to copy them
30- # into this layer.
12+ RUN --mount=type=cache,target=/root/.npm \
13+ npm install -g pnpm@${PNPM_VERSION}
14+
3115RUN --mount=type=bind,source=package.json,target=package.json \
32- --mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
33- --mount=type=cache,target=/root/.local/share/pnpm/store \
34- pnpm install --prod --frozen-lockfile
16+ --mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
17+ --mount=type=cache,target=/root/.local/share/pnpm/store \
18+ pnpm install --prod --frozen-lockfile
3519
36- # ###############################################################################
37- # Create a stage for building the application.
20+ # =================== build stage ============================================
3821FROM deps as build
3922
40- # Download additional development dependencies before building, as some projects require
41- # "devDependencies" to be installed to build. If you don't need this, remove this step.
4223RUN --mount=type=bind,source=package.json,target=package.json \
4324 --mount=type=bind,source=pnpm-lock.yaml,target=pnpm-lock.yaml \
4425 --mount=type=cache,target=/root/.local/share/pnpm/store \
4526 pnpm install --frozen-lockfile
4627
47- # Copy the rest of the source files into the image.
4828COPY . .
49- # Run the build script.
5029RUN pnpm run build
5130
52- # ###############################################################################
53- # Create a new stage to run the application with minimal runtime dependencies
54- # where the necessary files are copied from the build stage.
31+ # =================== final stage ============================================
5532FROM base as final
5633
57- # Use production node environment by default.
5834ENV NODE_ENV production
5935
60- # Run the application as a non-root user.
6136USER node
6237
63- # Copy package.json so that package manager commands can be used.
6438COPY package.json .
6539
66- # Copy the production dependencies from the deps stage and also
67- # the built application from the build stage into the image.
6840COPY --from=deps /usr/src/app/node_modules ./node_modules
6941COPY --from=build /usr/src/app/dist ./dist
7042
71-
72- # Expose the port that the application listens on.
7343EXPOSE 3000
7444
75- # Run the application.
76- CMD ["pnpm" , "run" , "start" ]
45+ CMD ["node" , "./dist/src/server.js" ]
0 commit comments