Skip to content

Commit 56e8454

Browse files
committed
feat: optimize Dockerfile for production with multi-stage build using Node 22
1 parent 4cea535 commit 56e8454

2 files changed

Lines changed: 16 additions & 4 deletions

File tree

Dockerfile

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM node:20-alpine AS builder
1+
# Stage 1: Build the static files
2+
FROM node:22-alpine AS builder
23

34
WORKDIR /app
45

@@ -18,8 +19,18 @@ RUN npm install --legacy-peer-deps
1819

1920
COPY . .
2021

22+
# Build the Docusaurus project
23+
RUN npm run build
24+
25+
# Stage 2: Serve the files using Nginx
26+
FROM nginx:alpine
27+
28+
# Copy the static files from builder stage
29+
# Docusaurus builds to the "build" directory by default
30+
COPY --from=builder /app/build /usr/share/nginx/html
31+
2132
# Expose the application port
22-
EXPOSE 3000
33+
EXPOSE 80
2334

24-
# Start the application
25-
CMD ["npm", "run", "dev", "--", "--host", "0.0.0.0"]
35+
# Start Nginx
36+
CMD ["nginx", "-g", "daemon off;"]

docker-compose.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ services:
22
recodehive:
33
build:
44
context: .
5+
target: builder
56
ports:
67
- "3000:3000"
78
volumes:

0 commit comments

Comments
 (0)