Skip to content

Commit be44a12

Browse files
committed
chore: refactor dockerfile for improved build and runtime
- Updated dockerfile to use multi-stage builds for better caching and smaller image size. - Added a .dockerignore file to exclude unnecessary files from the docker image. - Using pnpm for package management.
1 parent 56a7f52 commit be44a12

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

.dockerignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Dependencies
2+
node_modules
3+
4+
# Next.js build output
5+
.next
6+
7+
# Optional local environment variables
8+
.env.local
9+
.env.*.local
10+
11+
# Git
12+
.git
13+
.gitignore
14+
15+
# Docker
16+
Dockerfile
17+
.dockerignore
18+
19+
# Other
20+
README.md

Dockerfile

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,22 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM node:22-alpine AS builder
4-
3+
FROM node:22-slim AS base
4+
ENV PNPM_HOME="/pnpm"
5+
ENV CI="true"
6+
ENV PATH="$PNPM_HOME:$PATH"
7+
RUN corepack enable
8+
COPY . /app
59
WORKDIR /app
610

7-
RUN npm install -g pnpm
8-
9-
COPY package.json pnpm-lock.yaml ./
10-
11-
RUN pnpm install
12-
13-
COPY . .
11+
FROM base AS deps
12+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --prod --frozen-lockfile
1413

14+
FROM base AS build
15+
RUN --mount=type=cache,id=pnpm,target=/pnpm/store pnpm install --frozen-lockfile
1516
RUN pnpm run build
1617

17-
18-
FROM node:22-alpine AS runner
19-
20-
WORKDIR /app
21-
22-
COPY --from=builder /app/.next/standalone ./
23-
COPY --from=builder /app/.next/static ./.next/static
24-
COPY --from=builder /app/public ./public
25-
18+
FROM base AS runner
19+
COPY --from=deps /app/node_modules /app/node_modules
20+
COPY --from=build /app/.next /app/.next
2621
EXPOSE 3000
27-
28-
CMD ["node", "server.js"]
22+
CMD [ "pnpm", "start" ]

0 commit comments

Comments
 (0)