Skip to content

Commit

Permalink
Optimize Dockerfile and docker-compose.yml for multi-stage build and …
Browse files Browse the repository at this point in the history
…volume management
  • Loading branch information
arifszn committed Feb 6, 2025
1 parent 3dec4d3 commit 7b07fec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
18 changes: 9 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM node:22-slim

# Build stage
FROM node:22-slim AS builder
WORKDIR /usr/src/app

ARG PORT

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE ${PORT}

# Runtime stage
FROM node:22-slim as runner
WORKDIR /usr/src/app
COPY --from=builder /usr/src/app/node_modules ./node_modules
COPY . .
ARG APP_PORT
EXPOSE ${APP_PORT}
CMD ["npm", "run", "start:prod"]
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ services:
command: npm run start:dev
volumes:
- ./:/usr/src/app
- node_modules:/usr/src/app/node_modules
- /usr/src/app/node_modules
depends_on:
mysql:
condition: service_healthy
Expand Down Expand Up @@ -46,5 +46,3 @@ services:
volumes:
mysql:
driver: local
node_modules:
driver: local

0 comments on commit 7b07fec

Please sign in to comment.