your commit
This commit is contained in:
parent
ae3974383f
commit
791c0e54d3
1 changed files with 3 additions and 12 deletions
15
Dockerfile
15
Dockerfile
|
|
@ -1,26 +1,17 @@
|
|||
# To use this Dockerfile, you have to set `output: 'standalone'` in your next.config.js file.
|
||||
|
||||
FROM node:20-alpine AS base
|
||||
|
||||
# Install dependencies only when needed
|
||||
FROM base AS deps
|
||||
RUN apk add --no-cache libc6-compat
|
||||
WORKDIR /app
|
||||
|
||||
# Copy lockfile and install deps with pnpm
|
||||
COPY package.json pnpm-lock.yaml ./
|
||||
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate && pnpm i --frozen-lockfile
|
||||
|
||||
# Rebuild the source code only when needed
|
||||
FROM base AS builder
|
||||
WORKDIR /app
|
||||
COPY --from=deps /app/node_modules ./node_modules
|
||||
COPY . .
|
||||
|
||||
# Enable corepack again for build stage
|
||||
RUN corepack enable && corepack prepare pnpm@10.11.0 --activate && pnpm run build
|
||||
|
||||
# Production image, copy all the files and run next
|
||||
FROM base AS runner
|
||||
WORKDIR /app
|
||||
|
||||
|
|
@ -30,14 +21,14 @@ RUN addgroup --system --gid 1001 nodejs
|
|||
RUN adduser --system --uid 1001 nextjs
|
||||
|
||||
COPY --from=builder /app/public ./public
|
||||
COPY --from=builder /app/node_modules ./node_modules
|
||||
COPY --from=builder /app/package.json ./package.json
|
||||
|
||||
RUN mkdir .next
|
||||
RUN chown nextjs:nodejs .next
|
||||
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.bin/payload ./node_modules/.bin/payload
|
||||
COPY --from=builder --chown=nextjs:nodejs /app/node_modules/payload ./node_modules/payload
|
||||
|
||||
USER nextjs
|
||||
|
||||
|
|
@ -45,4 +36,4 @@ EXPOSE 3001
|
|||
ENV PORT=3001
|
||||
ENV HOSTNAME="0.0.0.0"
|
||||
|
||||
CMD ["sh", "-c", "find /app/node_modules -name 'payload.js' -path '*/bin/*' 2>/dev/null && node server.js"]
|
||||
CMD ["sh", "-c", "node node_modules/.bin/payload migrate && node server.js"]
|
||||
Loading…
Add table
Reference in a new issue