-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dockerfile
53 lines (40 loc) · 1.58 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
ARG BASE_IMAGE=node:16.16-alpine
# ------------------------------------- #
# Install dependencies only when needed #
# ------------------------------------- #
FROM $BASE_IMAGE AS deps
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile
# ---------------------------------------- #
# Rebuild the source code only when needed #
# ---------------------------------------- #
FROM $BASE_IMAGE AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG NODE_ENV=production
RUN echo ${NODE_ENV}
RUN NODE_ENV=${NODE_ENV} yarn build
# ------------------------------------------------- #
# Production image, copy all the files and run next #
# ------------------------------------------------- #
FROM $BASE_IMAGE AS runner
WORKDIR /app
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nextjs -u 1001
# Automatically leverages output traces to reduce image size
# https://nextjs.org/docs/advanced-features/output-file-tracing
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
# The standalone build of Next.js above does not include the public or static files so we copy these separately
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
COPY --from=builder /app/public ./public
USER nextjs
EXPOSE 80
ENV PORT 80
# Next.js collects completely anonymous telemetry data about general usage.
# Learn more here: https://nextjs.org/telemetry
# Uncomment the following line in case you want to disable telemetry.
ENV NEXT_TELEMETRY_DISABLED 1
# CMD is the command that runs when the container starts
CMD ["node", "server.js"]