ADD: Production multi-stage Dockerfile and .dockerignore
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
node_modules
|
||||||
|
npm-debug.log
|
||||||
|
logs
|
||||||
|
./logs
|
||||||
|
.git
|
||||||
|
.gitignore
|
||||||
|
.github
|
||||||
|
.idea
|
||||||
|
.vscode
|
||||||
|
.env
|
||||||
|
./config/.env
|
||||||
|
Dockerfile*
|
||||||
|
.dockerignore
|
||||||
|
README.md
|
||||||
+26
-11
@@ -1,20 +1,35 @@
|
|||||||
# Use the official Node.js image as a base
|
# Stage 1: Build & install production dependencies
|
||||||
FROM node:18
|
FROM node:20-alpine AS dependencies
|
||||||
|
|
||||||
# Set the working directory in the container
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
# Copy package.json and package-lock.json to the container
|
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies
|
RUN npm ci --omit=dev --ignore-scripts && npm cache clean --force
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
# Copy the rest of the application code
|
# Stage 2: Production runner
|
||||||
COPY . .
|
FROM node:20-alpine AS runner
|
||||||
|
|
||||||
# Expose the application port
|
WORKDIR /app
|
||||||
|
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV PORT=3000
|
||||||
|
|
||||||
|
# Install dumb-init for robust signal handling (PID 1)
|
||||||
|
RUN apk add --no-cache dumb-init && mkdir -p /app/uploads && chown -R node:node /app
|
||||||
|
|
||||||
|
# Switch to non-root user
|
||||||
|
USER node
|
||||||
|
|
||||||
|
# Copy production node_modules with ownership
|
||||||
|
COPY --chown=node:node --from=dependencies /app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy application source code with ownership
|
||||||
|
COPY --chown=node:node . .
|
||||||
|
|
||||||
|
# Expose backend port
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Start the application
|
# Run container with dumb-init
|
||||||
CMD ["npm", "start"]
|
ENTRYPOINT ["/usr/bin/dumb-init", "--"]
|
||||||
|
CMD ["node", "app.js"]
|
||||||
|
|||||||
Reference in New Issue
Block a user