philschmid commited on
Commit
f1f420e
·
verified ·
1 Parent(s): b4672c9

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +30 -25
Dockerfile CHANGED
@@ -1,20 +1,19 @@
1
- # syntax=docker/dockerfile:1.4
2
 
3
- # Adapted from https://github.com/vercel/next.js/blob/e60a1e747c3f521fc24dfd9ee2989e13afeb0a9b/examples/with-docker/Dockerfile
4
- # For more information, see https://nextjs.org/docs/pages/building-your-application/deploying#docker-image
5
-
6
- FROM node:22 AS base
7
 
8
  # Install dependencies only when needed
9
  FROM base AS deps
 
 
10
  WORKDIR /app
11
 
12
  # Install dependencies based on the preferred package manager
13
- COPY --link package.json yarn.lock* package-lock.json* pnpm-lock.yaml* ./
14
  RUN \
15
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
16
  elif [ -f package-lock.json ]; then npm ci; \
17
- elif [ -f pnpm-lock.yaml ]; then yarn global add pnpm && pnpm i --frozen-lockfile; \
18
  else echo "Lockfile not found." && exit 1; \
19
  fi
20
 
@@ -22,40 +21,46 @@ RUN \
22
  # Rebuild the source code only when needed
23
  FROM base AS builder
24
  WORKDIR /app
25
- COPY --from=deps --link /app/node_modules ./node_modules
26
- COPY --link . .
27
-
28
- ENV NEXT_TELEMETRY_DISABLED 1
29
 
30
- RUN npm run build
 
 
 
31
 
32
- # If using yarn comment out above and use below instead
33
- # RUN yarn build
 
 
 
 
34
 
35
  # Production image, copy all the files and run next
36
  FROM base AS runner
37
  WORKDIR /app
38
 
39
- ENV NODE_ENV production
40
- ENV NEXT_TELEMETRY_DISABLED 1
 
41
 
42
- RUN \
43
- addgroup --system --gid 1001 nodejs; \
44
- adduser --system --uid 1001 nextjs
45
 
46
- COPY --from=builder --link /app/public ./public
47
 
48
  # Automatically leverage output traces to reduce image size
49
  # https://nextjs.org/docs/advanced-features/output-file-tracing
50
- COPY --from=builder --link --chown=1001:1001 /app/.next/standalone ./
51
- COPY --from=builder --link --chown=1001:1001 /app/.next/static ./.next/static
52
 
53
  USER nextjs
54
 
55
  EXPOSE 3000
56
 
57
- ENV PORT 3000
58
- ENV HOSTNAME 0.0.0.0
59
-
60
 
 
 
 
61
  CMD ["node", "server.js"]
 
1
+ # syntax=docker.io/docker/dockerfile:1
2
 
3
+ FROM node:22-alpine AS base
 
 
 
4
 
5
  # Install dependencies only when needed
6
  FROM base AS deps
7
+ # Check https://github.com/nodejs/docker-node/tree/b4117f9333da4138b03a546ec926ef50a31506c3#nodealpine to understand why libc6-compat might be needed.
8
+ RUN apk add --no-cache libc6-compat
9
  WORKDIR /app
10
 
11
  # Install dependencies based on the preferred package manager
12
+ COPY package.json yarn.lock* package-lock.json* pnpm-lock.yaml* .npmrc* ./
13
  RUN \
14
  if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
15
  elif [ -f package-lock.json ]; then npm ci; \
16
+ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
17
  else echo "Lockfile not found." && exit 1; \
18
  fi
19
 
 
21
  # Rebuild the source code only when needed
22
  FROM base AS builder
23
  WORKDIR /app
24
+ COPY --from=deps /app/node_modules ./node_modules
25
+ COPY . .
 
 
26
 
27
+ # Next.js collects completely anonymous telemetry data about general usage.
28
+ # Learn more here: https://nextjs.org/telemetry
29
+ # Uncomment the following line in case you want to disable telemetry during the build.
30
+ # ENV NEXT_TELEMETRY_DISABLED=1
31
 
32
+ RUN \
33
+ if [ -f yarn.lock ]; then yarn run build; \
34
+ elif [ -f package-lock.json ]; then npm run build; \
35
+ elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
36
+ else echo "Lockfile not found." && exit 1; \
37
+ fi
38
 
39
  # Production image, copy all the files and run next
40
  FROM base AS runner
41
  WORKDIR /app
42
 
43
+ ENV NODE_ENV=production
44
+ # Uncomment the following line in case you want to disable telemetry during runtime.
45
+ # ENV NEXT_TELEMETRY_DISABLED=1
46
 
47
+ RUN addgroup --system --gid 1001 nodejs
48
+ RUN adduser --system --uid 1001 nextjs
 
49
 
50
+ COPY --from=builder /app/public ./public
51
 
52
  # Automatically leverage output traces to reduce image size
53
  # https://nextjs.org/docs/advanced-features/output-file-tracing
54
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
55
+ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
56
 
57
  USER nextjs
58
 
59
  EXPOSE 3000
60
 
61
+ ENV PORT=3000
 
 
62
 
63
+ # server.js is created by next build from the standalone output
64
+ # https://nextjs.org/docs/pages/api-reference/config/next-config-js/output
65
+ ENV HOSTNAME="0.0.0.0"
66
  CMD ["node", "server.js"]