DevJourney · code I wrote while learning
Dockerfile
1.8 KBARG NODE_VERSION=24
################################################################################
# Use node image for base image for all stages.
FROM node:${NODE_VERSION}-alpine AS base
# Set working directory for all build stages.
WORKDIR /usr/src/app
################################################################################
# Create a stage for installing production dependencies.
FROM base AS deps
# corepack is no longer shipped in Node >= 25; install pnpm directly
RUN npm install -g pnpm@11
# Copy manifests so the dependency layer can be cached.
COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./
RUN pnpm install --frozen-lockfile
################################################################################
# Create a stage for building the application.
FROM deps AS build
# Copy the rest of the source files into the image.
COPY . .
# Run the build script.
RUN pnpm run build
################################################################################
# Create a new stage to run the application with minimal runtime dependencies
# where the necessary files are copied from the build stage.
FROM base AS final
# Use production node environment by default.
ENV NODE_ENV=production
ENV ORIGIN=https://qwik.dj.upayan.dev
# Run the application as a non-root user.
USER node
# Copy package.json so that package manager commands can be used.
COPY package.json .
# Copy the production dependencies from the deps stage and also
# the built application from the build stage into the image.
COPY --from=deps /usr/src/app/node_modules ./node_modules
COPY --from=build /usr/src/app/dist ./dist
COPY --from=build /usr/src/app/server ./server
# Expose the port that the application listens on.
EXPOSE 3000
# Run the application.
CMD ["node", "server/entry.express"]