Skip to content

Commit

Permalink
build: add nextjs dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelgautier committed Aug 8, 2024
1 parent 69a3639 commit 04b75cc
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
43 changes: 43 additions & 0 deletions examples/nextjs-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
FROM node:20 as builder

WORKDIR /app

COPY package*.json ./
RUN npm ci

COPY . .

ENV NEXT_BUILD_OUTPUT 'standalone'

RUN npm run build

FROM node:20-alpine

WORKDIR /app

ENV NODE_ENV production

RUN addgroup --system --gid 1001 nodejs && \
adduser --system --uid 1001 nextjs

COPY --from=builder /app/public ./public

# Set the correct permission for prerender cache
RUN mkdir .next && \
chown nextjs:nodejs .next

# Automatically leverage output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static

USER nextjs

EXPOSE 3000

ENV PORT 3000
ENV HOSTNAME "0.0.0.0"

# server.js is created by next build from the standalone output
# https://nextjs.org/docs/pages/api-reference/next-config-js/output
CMD ["node", "server.js"]
4 changes: 3 additions & 1 deletion examples/nextjs-app/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @type {import('next').NextConfig} */
const nextConfig = {};
const nextConfig = {
output: process.env.NEXT_BUILD_OUTPUT,
};

export default nextConfig;

0 comments on commit 04b75cc

Please sign in to comment.