build: optimize Docker image with multi-stage build and security improvements
- Implement multi-stage build to reduce final image size - Install only production dependencies with npm ci --only=production - Clean npm cache to reduce image size - Improve layer caching by copying package files before application code - Update package version from 1.0.0 to 1.0.1
This commit is contained in:
25
Dockerfile
25
Dockerfile
@@ -1,15 +1,22 @@
|
|||||||
FROM node:23-slim
|
FROM node:24-slim AS builder
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
# Copy dependency files first
|
||||||
|
COPY package*.json ./
|
||||||
|
|
||||||
|
# Install production dependencies only
|
||||||
|
RUN npm ci --only=production && npm cache clean --force
|
||||||
|
|
||||||
|
FROM node:24-slim
|
||||||
|
|
||||||
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
COPY --from=builder /usr/src/app/node_modules ./node_modules
|
||||||
|
|
||||||
|
# Copy application code
|
||||||
|
COPY . .
|
||||||
|
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
COPY package.json /usr/src/app/package.json
|
|
||||||
|
|
||||||
RUN npm install
|
|
||||||
|
|
||||||
USER node
|
|
||||||
|
|
||||||
COPY . /usr/src/app/
|
|
||||||
|
|
||||||
CMD ["npm", "start"]
|
CMD ["npm", "start"]
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "no-as-service",
|
"name": "no-as-service",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"description": "A lightweight API that returns random rejection or no reasons.",
|
"description": "A lightweight API that returns random rejection or no reasons.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in New Issue
Block a user