# syntax=docker/dockerfile:1 # ---- deps: install once, reused by the build stage ---- FROM node:24-alpine AS deps WORKDIR /app # Prisma's engine binaries need OpenSSL; libc6-compat smooths over a few # other native-module quirks on Alpine. RUN apk add --no-cache libc6-compat openssl COPY package.json package-lock.json ./ RUN npm ci # ---- build: generate the Prisma client and compile the Next.js app ---- FROM node:24-alpine AS build WORKDIR /app RUN apk add --no-cache openssl COPY --from=deps /app/node_modules ./node_modules COPY . . RUN npx prisma generate RUN npm run build # ---- runtime ---- # Not using Next's `output: "standalone"` here: its dependency tracing # only follows what the server bundle imports, so it wouldn't include the # Prisma CLI, which this image invokes as a separate process (via # docker-entrypoint.sh) to run migrations on every container start. Copying # the full node_modules is a simpler, more reliable trade for a # single self-hosted instance. FROM node:24-alpine AS runtime WORKDIR /app ENV NODE_ENV=production RUN apk add --no-cache openssl COPY --from=build /app/node_modules ./node_modules COPY --from=build /app/.next ./.next COPY --from=build /app/public ./public COPY --from=build /app/prisma ./prisma COPY --from=build /app/lib ./lib COPY --from=build /app/prisma.config.ts ./prisma.config.ts COPY --from=build /app/package.json ./package.json COPY --from=build /app/next.config.ts ./next.config.ts COPY docker-entrypoint.sh ./docker-entrypoint.sh # Strip any CRLF line endings before making it executable -- a CRLF # shebang (e.g. from a Windows checkout without .gitattributes honoring # `eol=lf`) makes the kernel look for a literal "/bin/sh\r" interpreter, # which fails with a misleading "no such file or directory" at container # startup. This keeps the image correct even if the checkout wasn't. RUN sed -i 's/\r$//' docker-entrypoint.sh && chmod +x docker-entrypoint.sh EXPOSE 3000 ENTRYPOINT ["./docker-entrypoint.sh"] CMD ["npm", "run", "start"]