Last active
June 10, 2024 03:49
-
-
Save dattp/7c6babfbd04b6fbcfd9691dd0899c66c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DOCKER_BUILDKIT=1 docker build -t webapp:v1 --build-arg NEXT_ENVIRONMENT=development --build-arg BUILDKIT_INLINE_CACHE=1 . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Install dependencies only when needed | |
FROM node:18-alpine AS builder | |
WORKDIR /app | |
RUN apk add --no-cache libc6-compat && rm -rf /var/cache/apk/* | |
ARG NEXT_ENVIRONMENT | |
ENV NODE_ENV $NEXT_ENVIRONMENT | |
ENV NEXT_PUBLIC_ENV $NEXT_ENVIRONMENT | |
# RUN mkdir -p .next/cache | |
COPY package.json yarn.lock ./ | |
# Use Docker BuildKit to mount the cache | |
RUN --mount=type=cache,target=/root/.yarn/cache \ | |
--mount=type=cache,target=/app/.next/cache \ | |
yarn install --pure-lockfile | |
COPY . . | |
COPY .env.${NEXT_ENVIRONMENT} .env.production | |
# Build the Next.js application | |
RUN --mount=type=cache,target=/app/.next/cache \ | |
yarn build | |
# Remove dev dependencies | |
RUN --mount=type=cache,target=/app/.next/cache \ | |
yarn install --pure-lockfile --prod | |
FROM node:18-alpine | |
WORKDIR /app | |
EXPOSE 3000 | |
ENV PORT 3000 | |
# Uncomment the following line in case you want to disable telemetry during runtime. | |
# ENV NEXT_TELEMETRY_DISABLED 1 | |
RUN addgroup --system --gid 1001 nodejs | |
RUN adduser --system --uid 1001 nextjs | |
# You only need to copy next.config.js if you are NOT using the default configuration | |
# COPY --from=builder /app/next.config.js ./ | |
COPY --from=builder /app/public ./public | |
COPY --from=builder /app/package.json ./package.json | |
COPY --from=builder /app/node_modules ./node_modules | |
COPY --from=builder /app/.next/standalone ./ | |
COPY --from=builder /app/.next/static ./.next/static | |
USER nextjs | |
CMD ["npm", "run", "start"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
log build in local