37 lines
742 B
Docker
37 lines
742 B
Docker
# Build Stage
|
|
FROM node:lts-alpine AS build-stage
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Install app dependencies
|
|
COPY package*.json ./
|
|
|
|
RUN npm install
|
|
|
|
# Copy source files and build the app
|
|
COPY . .
|
|
RUN npm run build
|
|
|
|
# Production Stage
|
|
FROM node:lts-alpine
|
|
|
|
ENV NODE_ENV=production
|
|
|
|
# Create app directory
|
|
WORKDIR /app
|
|
|
|
# Install only production dependencies as root first
|
|
COPY package*.json ./
|
|
RUN npm install --production && npm cache clean --force
|
|
|
|
# Copy built app from build stage
|
|
COPY --from=build-stage /app/dist ./dist
|
|
|
|
# Change ownership to node user and switch to node user
|
|
RUN chown -R node:node /app
|
|
USER node
|
|
|
|
# Define the entrypoint and default command
|
|
# If you have a custom entrypoint script
|
|
CMD [ "node", "dist/app.js" ]
|