nextload/Dockerfile

39 lines
890 B
Docker
Raw Normal View History

2024-06-05 20:25:53 +00:00
FROM node:lts as base
2024-06-05 20:41:46 +00:00
2024-06-06 06:05:16 +00:00
# Set environment variables for pnpm
2024-06-05 20:41:46 +00:00
ENV PNPM_HOME="/pnpm"
ENV PATH="$PNPM_HOME:$PATH"
RUN corepack enable
2024-06-05 20:25:53 +00:00
WORKDIR /base
2024-06-05 20:33:56 +00:00
COPY package.json pnpm-lock.yaml ./
2024-06-06 06:05:16 +00:00
RUN pnpm install --frozen-lockfile
2024-06-05 20:25:53 +00:00
COPY . .
2024-06-06 06:05:16 +00:00
# Build stage: build the Next.js application
FROM base as build
2024-06-05 20:25:53 +00:00
ENV NODE_ENV=production
2024-06-06 06:05:16 +00:00
WORKDIR /base
2024-06-05 20:31:53 +00:00
RUN pnpm build
2024-06-05 20:25:53 +00:00
2024-06-06 06:05:16 +00:00
# Production stage: serve the application
FROM node:lts as prod
2024-06-05 20:25:53 +00:00
ENV NODE_ENV=production
2024-06-06 06:05:16 +00:00
WORKDIR /app
# Copy package files and install production dependencies
COPY package.json pnpm-lock.yaml ./
2024-06-05 20:31:53 +00:00
RUN pnpm install --production
2024-06-05 20:25:53 +00:00
2024-06-06 06:05:16 +00:00
# Copy build artifacts from the build stage
COPY --from=build /base/.next ./.next
COPY --from=build /base/public ./public
COPY --from=build /base/next.config.js ./
2024-06-05 20:25:53 +00:00
EXPOSE 3000
COPY docker-entrypoint.sh /docker-entrypoint.sh
2024-06-06 06:05:16 +00:00
RUN chmod +x /docker-entrypoint.sh
2024-06-05 20:25:53 +00:00
ENTRYPOINT ["/docker-entrypoint.sh"]
2024-06-06 06:05:16 +00:00
CMD ["pnpm", "start"]