Skip to content

Commit 4b067ff

Browse files
committed
feat: docker setup
1 parent 71db0af commit 4b067ff

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

Dockerfile

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Install dependencies only when needed
2+
FROM node:20-alpine AS deps
3+
# Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
4+
RUN apk add --no-cache libc6-compat
5+
WORKDIR /app
6+
7+
# Install dependencies based on the preferred package manager
8+
COPY package.json yarn.lock* pnpm-lock.yaml* ./
9+
RUN \
10+
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
11+
elif [ -f package-lock.json ]; then npm ci; \
12+
elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
13+
else echo "Lockfile not found." && exit 1; \
14+
fi
15+
16+
17+
# Rebuild the source code only when needed
18+
FROM node:20-alpine AS builder
19+
WORKDIR /app
20+
COPY . .
21+
22+
RUN yarn install --force
23+
24+
RUN yarn build
25+
26+
# If using npm comment out above and use below instead
27+
# RUN npm run build
28+
29+
# Production image, copy all the files and run next
30+
FROM node:20-alpine AS runner
31+
WORKDIR /app
32+
33+
ENV NODE_ENV production
34+
# Uncomment the following line in case you want to disable telemetry during runtime.
35+
ENV NEXT_TELEMETRY_DISABLED 1
36+
37+
RUN addgroup --system --gid 1001 nodejs
38+
RUN adduser --system --uid 1001 nextjs
39+
40+
# COPY --from=builder /app/public ./public
41+
42+
# Automatically leverage output traces to reduce image size
43+
# https://nextjs.org/docs/advanced-features/output-file-tracing
44+
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
45+
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
46+
# COPY --from=builder --chown=nextjs:nodejs /app/public ./public
47+
48+
USER nextjs
49+
50+
EXPOSE 3000
51+
52+
ENV PORT 3000
53+
54+
CMD ["node", "server.js"]

next.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import type { NextConfig } from "next";
22

33
const nextConfig: NextConfig = {
4+
5+
output: "standalone",
6+
47
/* config options here */
58
env: {
69
API_URL: process.env.API_URL,

0 commit comments

Comments
 (0)