1- # app/Dockerfile
1+ # Use a small official Node.js 20 image from AWS Public ECR (Alpine-based for minimal size)
22FROM public.ecr.aws/docker/library/node:20-alpine
33
4+ # Set working directory inside the container
45WORKDIR /app
56
6- # Copy only manifests first to leverage layer cache
7+ # Copy only dependency manifests first (package.json, package-lock.json)
8+ # This allows Docker to cache dependency installation layers
9+ # unless package files have changed (faster builds).
710COPY package*.json ./
811
9- # Install production dependencies
12+ # Install production dependencies only
13+ # "npm ci" ensures clean, reproducible installs
14+ # "--omit=dev" excludes devDependencies → smaller image, faster runtime
1015RUN npm ci --omit=dev
1116
12- # Copy source
17+ # Copy the application source code
18+ # Here we assume all source is inside "src/" directory
1319COPY src ./src
1420
21+ # Set environment variables for production
1522ENV NODE_ENV=production
1623ENV PORT=80
1724
18- # Lightweight healthcheck (no curl/wget needed)
19- HEALTHCHECK --interval=30s --timeout=3s --start-period=10s CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
25+ # Define container health check
26+ # - Interval: every 30s
27+ # - Timeout: fail after 3s
28+ # - Start period: allow 10s before first check
29+ # - Command: Run a Node one-liner that makes HTTP request to /health endpoint
30+ # → exits 0 if OK, exits 1 if failure
31+ # Using Node's fetch avoids installing curl or wget, keeping the image slim.
32+ HEALTHCHECK --interval=30s --timeout=3s --start-period=10s \
33+ CMD node -e "fetch('http://127.0.0.1:'+process.env.PORT+'/health').then(r=>process.exit(r.ok?0:1)).catch(()=>process.exit(1))"
2034
35+ # Expose application port (for ECS, Kubernetes, etc.)
2136EXPOSE 80
22- CMD ["npm" , "start" ]
37+
38+ # Default container startup command → "npm start" defined in package.json
39+ CMD ["npm" , "start" ]
0 commit comments