fartak/Dockerfile

41 lines
942 B
Docker

# ---- Base Stage ----
FROM node:20-slim AS base
# ---- Build Stage ----
FROM base AS build
WORKDIR /app
COPY package.json package-lock.json ./
# Install ALL dependencies (dev and prod)
# This is cached and only re-runs if the lockfile changes.
RUN npm ci
# Copy the rest of the source code
COPY . .
# Build the application
RUN npm run build
# ---- Production Stage ----
# Create the final, lean production image by copying only what's needed.
# This stage is very fast as it only contains COPY commands.
FROM base AS production
WORKDIR /app
# Copy the pruned production dependencies, the built app, and package.json
COPY --from=build /app/node_modules ./node_modules
COPY --from=build /app/dist ./dist
COPY --from=build /app/package.json ./package.json
# Expose the port the app runs on
EXPOSE 3000
# Run the application as a non-root user for better security
USER node
# Command to run the application
CMD ["node", "dist/main"]