Skip to content

Commit 5a87409

Browse files
committed
chore: update container image
1 parent 7db730a commit 5a87409

File tree

1 file changed

+8
-60
lines changed

1 file changed

+8
-60
lines changed

Dockerfile

Lines changed: 8 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,15 @@
1-
FROM node:20-alpine AS base
1+
FROM node:20-alpine as build
22

3-
# Install dependencies only when needed
4-
FROM base AS deps
5-
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
6-
RUN apk add --no-cache libc6-compat
73
WORKDIR /app
84

9-
# Install dependencies based on the preferred package manager
10-
COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
11-
RUN \
12-
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
13-
elif [ -f package-lock.json ]; then npm ci; \
14-
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
15-
else echo "Lockfile not found." && exit 1; \
16-
fi
5+
COPY package.json package-lock.* ./
6+
RUN npm install
177

18-
19-
# Rebuild the source code only when needed
20-
FROM base AS builder
21-
WORKDIR /app
22-
COPY --from=deps /app/node_modules ./node_modules
8+
# Build the application
239
COPY . .
10+
RUN npm run build
2411

25-
# Next.js collects completely anonymous telemetry data about general usage.
26-
# Learn more here: https://nextjs.org/telemetry
27-
# Uncomment the following line in case you want to disable telemetry during the build.
28-
# ENV NEXT_TELEMETRY_DISABLED=1
29-
30-
RUN \
31-
if [ -f yarn.lock ]; then yarn run build; \
32-
elif [ -f package-lock.json ]; then npm run build; \
33-
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
34-
else echo "Lockfile not found." && exit 1; \
35-
fi
36-
37-
# Production image, copy all the files and run next
38-
FROM base AS runner
39-
WORKDIR /app
40-
41-
ENV NODE_ENV=production
42-
# Uncomment the following line in case you want to disable telemetry during runtime.
43-
# ENV NEXT_TELEMETRY_DISABLED=1
44-
45-
RUN addgroup --system --gid 1001 nodejs
46-
RUN adduser --system --uid 1001 nextjs
47-
48-
COPY --from=builder /app/public ./public
49-
50-
# Set the correct permission for prerender cache
51-
RUN mkdir .next
52-
RUN chown nextjs:nodejs .next
53-
54-
# Automatically leverage output traces to reduce image size
55-
# https://nextjs.org/docs/advanced-features/output-file-tracing
56-
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
57-
58-
USER nextjs
59-
60-
EXPOSE 3000
61-
62-
ENV PORT=3000
12+
# ====================================
13+
FROM build as release
6314

64-
# server.js is created by next build from the standalone output
65-
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
66-
ENV HOSTNAME="0.0.0.0"
67-
CMD ["node", "server.js"]
15+
CMD ["npm", "run", "start"]

0 commit comments

Comments
 (0)