1- # ------------------------
2- # Stage 1: Build Stage
3- # ------------------------
4- FROM node:20-alpine AS builder
1+ # Use a slim Node.js image as base
2+ FROM node:20-alpine
53
6- # Set working directory
4+ # Install docker CLI to execute docker command (for accessing host Docker)
5+ # Also install bash for better scripting capabilities inside the container if needed
6+ RUN apk add --no-cache docker-cli bash
7+
8+ # Set working directory inside the container
79WORKDIR /app
810
9- # Copy only package files to install dependencies first (cache-friendly)
11+ # Copy only package.json and package-lock.json to leverage Docker layer caching
12+ # This ensures npm install is re-run only if dependencies change
1013COPY package*.json ./
1114
12- # Install dependencies
15+ # Install project dependencies
1316RUN npm install
1417
15- # Copy the rest of the app source code
18+ # Copy the rest of your application source code
1619COPY . .
1720
18- # ------------------------
19- # Stage 2: Production Image
20- # ------------------------
21- FROM node:20-alpine AS production
21+ # Set environment variables
22+ ENV PORT=5000
2223
23- # Set working directory
24- WORKDIR /app
24+ # Create a temporary directory that will be used for mounting (if it doesn't exist on host)
25+ # This command ensures the directory exists within the image,
26+ # but the volume mount `./temp:/app/temp` will override it with the host's `./temp`
27+ # if `./temp` exists on the host. If `./temp` doesn't exist on the host, Docker will create it.
28+ RUN mkdir -p /app/temp
2529
26- # Copy only the necessary files from builder
27- COPY --from=builder /app/node_modules ./node_modules
28- COPY --from=builder /app/package*.json ./
29- # COPY --from=builder /app/dist ./dist
30- # COPY --from=builder /app/temp ./temp
31- COPY --from=builder /app/views ./views
32- COPY --from=builder /app/*.js ./
30+ # Expose the port your Node.js application listens on
31+ EXPOSE 5000
3332
34- # Set environment variables
35- ENV NODE_ENV=production
36- ENV PORT=5000
33+ # Command to run your application when the container starts
34+ CMD ["npm" , "run" , "start" ]
35+
36+
37+ # # ------------------------
38+ # # Stage 1: Build Stage
39+ # # ------------------------
40+ # FROM node:20-alpine AS builder
41+
42+ # # Set working directory
43+ # WORKDIR /app
44+
45+ # # Copy only package files to install dependencies first (cache-friendly)
46+ # COPY package*.json ./
47+
48+ # # Install dependencies
49+ # RUN npm install
50+
51+ # # Copy the rest of the app source code
52+ # COPY . .
53+
54+ # # ------------------------
55+ # # Stage 2: Production Image
56+ # # ------------------------
57+ # FROM node:20-alpine AS production
58+
59+ # # Set working directory
60+ # WORKDIR /app
61+
62+ # # Copy only the necessary files from builder
63+ # COPY --from=builder /app/node_modules ./node_modules
64+ # COPY --from=builder /app/package*.json ./
65+ # # COPY --from=builder /app/dist ./dist
66+ # # COPY --from=builder /app/temp ./temp
67+ # COPY --from=builder /app/views ./views
68+ # COPY --from=builder /app/*.js ./
69+ # COPY --form=builder /app/.git ./
3770
38- # Expose app port
39- EXPOSE 5000
71+ # # Set environment variables
72+ # ENV NODE_ENV=production
73+ # ENV PORT=5000
4074
41- # Start the application
42- CMD [ "node" , "index.js" ]
75+ # # Expose app port
76+ # EXPOSE 5000
4377
78+ # # Start the application
79+ # CMD ["node", "index.js"]
0 commit comments