How to start Prisma with `distroless/nodejs22-debian12` image?
Hi team,
I'm currently building a Docker image using gcr.io/distroless/nodejs22-debian12:nonroot as the base for the production stage. Here's the relevant part of the Dockerfile:
FROM gcr.io/distroless/nodejs22-debian12:nonroot AS production
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/.env .env
COPY --from=build /app/node_modules ./node_modules
CMD ["dist/src/main", ";prisma migrate deploy; prisma db seed"]
I'm trying to understand: Is it possible to run Prisma commands (e.g., prisma migrate deploy, prisma db seed) in a distroless image? If so, how should I properly structure the CMD or ENTRYPOINT to support this? Are there any best practices or recommendations to achieve this cleanly?
Any guidance or examples would be much appreciated! Thanks in advance 🙏
@siddjellali
Hello, you can't invoke prisma commands in distroless images because by default it does not have shells etc and nodejs image's entrypoint is node. So you should to prisma commands in build step like this (it's an example Dockefile I use for one of my projects)
FROM node:22-bullseye AS base
FROM base AS deps
WORKDIR /deps
COPY package.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm i --frozen-lockfile --ignore-scripts
FROM base AS build
WORKDIR /build
COPY --from=deps /deps/node_modules ./node_modules
COPY . .
RUN corepack enable pnpm && pnpm prisma generate && pnpm build
FROM gcr.io/distroless/nodejs22-debian12:nonroot
WORKDIR /app
USER nonroot
COPY --from=build /build/.output ./output
ENV NODE_ENV=production
ENV HOSTNAME=0.0.0.0
ENV PORT=3000
EXPOSE 3000
CMD ["output/server/index.mjs"]