For my project, it seems to work fine by using the following structure. Only 2 folder needed (dist, node_modules) and 2 files (package.json and package-lock.json)

######### First Stage #############

FROM node:20-alpine AS development

WORKDIR /app

COPY --chown=node:node ./app ./

RUN npm ci \
    && npx prisma generate \
    && npm run build \
    && npm prune --omit=dev


######### Second Stage #############

FROM node:20-alpine AS production

WORKDIR /var/www/app

# Create the necessary directories with correct permissions
COPY --chown=node:node --from=development /app/node_modules ./node_modules
COPY --chown=node:node --from=development /app/dist ./dist
COPY --chown=node:node --from=development /app/package*.json ./

# Switch to the non-root user
USER node

EXPOSE 3000

CMD ["node", "dist/src/main"]

where my project folder has the following structure:

/myproject
  Dockerfile
  /app
    package.json
    ...
    ... (other nestjs files)
    ...
    /src
       /prisma

package.json definition:

....
  "prisma": {
    "schema": "./src/prisma/schema.prisma"
  }
....

Hope it helps.

🌐
Prisma
prisma.io › home › docker › docker › docker
How to use Prisma in Docker | Prisma Documentation
This should generate a migrations folder in the prisma folder and the Prisma Client in the generated/prisma_client directory. ... No users have been added yet. Stop the local server. Once testing is complete, remove the standalone PostgreSQL container: docker compose -f docker-compose.postgres.yml ...
🌐
Reddit
reddit.com › r/node › how to dockerize node + prisma
r/node on Reddit: How to dockerize Node + Prisma
April 3, 2023 -

TLDR: Does anyone have a tutorial on how to set up Node (Next.js) + Prisma + Postgres with Docker Compose in 2023?

Hey everyone! I'm a junior Python developer who has been getting into web dev lately, and I've been struggling on a problem for days without a solution. I was hoping someone here might be able to help!

Specifically, I'm having trouble dockerizing a Next.js application that uses Prisma + Postgres. I'm hoping someone might be able to provide some guidance on how to do this in 2023. All of the tutorials I've seen have had different methods of doing this, some using deprecated compose features, some setting up Prisma as a separate service, etc. Any guidance is appreciated!

🌐
Stack Overflow
stackoverflow.com › questions › 75954535 › how-to-use-prisma-to-generate-database-tables-in-docker
node.js - How to use Prisma to generate database tables in Docker - Stack Overflow
That means that I'm assuming that no existing database volume exists, so, upon building the images, Docker needs to · Create a users database in the Postgres container (? I'm not sure if this is created by default as defined in the connection URL) Create a users table within that database, which I'm hoping to do with npx prisma db push so that the schema.prisma file is used
🌐
GitHub
github.com › prisma › prisma › issues › 21241
Bun: Can't `prisma generate` on Docker · Issue #21241 · prisma/prisma
September 27, 2023 - Bug description Trying to running prisma generate inside Docker container build, but it does not happen. See console output: It started some Prisma engine downloading, but gives up in about 1~2 sec...
Author   prisma
🌐
Prisma
v1.prisma.io › docs › 1.34 › prisma-server › deployment-environments › docker-rty1
Prisma 1.34 - Docker
Overview Prisma servers can be run with Docker. This page contains everything you need to know around the Docker setup and relevant worfklows.
🌐
textbook
blog.jonrshar.pe › 2024 › Dec › 24 › nextjs-prisma-docker.html
textbook - Next.js and Prisma in Docker
December 24, 2024 - Prisma is an ORM (object-relational ... storing and retrieving objects in the database. It generates a type-safe client (using TypeScript types) matching your schema, to give better IDE support while interacting with the ...
Find elsewhere
🌐
Adamjberkowitz
adamjberkowitz.com › blog › post › starting-with-prisma-and-docker
Adam Berkowitz - Starting with Prisma and Docker
When you install prisma in your project and use the prisma init command, the CLI lets you choose to use a new or existing database and have it "Set up a new Prisma server for local development (based on docker-compose)". Next you can choose ...
🌐
Code Mochi
codemochi.com › blog › 2022-01-01-dockerizing-nextjs-with-prisma-for-production
Dockerizing Next.js with Prisma for Production Environments | Code Mochi
You can use nvm to set the version and node --version to check that they are the same. Then you can runnpm run prisma:generate which will generate the library followed by npm run prisma:migrate to create a dev.db file.
🌐
Tericcabrel
blog.tericcabrel.com › build-docker-image-nodejs-prisma
Build the Docker image of a Node.js project using Prisma
June 25, 2024 - In the project root directory, create a Dockerfile and add the content below: FROM node:20-bullseye as builder RUN mkdir app WORKDIR /app COPY . . RUN yarn install --frozen-lockfile RUN yarn prisma generate RUN yarn tsc FROM node:20-alpine AS runner ENV NODE_ENV=production WORKDIR /app COPY --chown=node:node --from=builder /app/package.json .
🌐
notiz
notiz.dev › blog › dockerizing-nestjs-with-prisma-and-postgresql
Dockerizing a NestJS app with Prisma and PostgreSQL
# A wildcard is used to ensure both package.json AND package-lock.json are copied COPY package*.json ./ COPY prisma ./prisma/ # Install app dependencies RUN npm install · Next you need to install your app dependencies inside the Docker image. package.json and package-lock.json are copied over. Generating the Prisma Client requires the schema.prisma file.
🌐
DhiWise
dhiwise.com › post › how-to-build-app-with-nextjs-prisma-and-docker
Building App with Next.js, Prisma, and Docker
November 7, 2024 - It allows you to work with data seamlessly by defining models in the prisma schema file, then generating the Prisma client, which lets you run queries directly from your Next.js app.
Top answer
1 of 16
41

Just remove the following line from the schema.prisma file:

output   = "../generated/prisma"

and execute:

npx prisma generate
2 of 16
18

I know that this has been marked as solved, but I just wanted to share my setup for anyone interested.

Dockerfile

# Build image
FROM node:16.13-alpine as builder
WORKDIR /app

# Not sure if you will need this
# RUN apk add --update openssl

COPY package*.json ./
RUN npm ci --quiet

COPY ./prisma prisma
COPY ./src src
RUN npm run build

# Production image

FROM node:16.13-alpine
WORKDIR /app
ENV NODE_ENV production

COPY package*.json ./
RUN npm ci --only=production --quiet

COPY --chown=node:node --from=builder /app/prisma /app/prisma
COPY --chown=node:node --from=builder /app/src /app/src

USER node

EXPOSE 8080
CMD ["node", "src/index.js"]

package.json

{
  "name": "example",
  "description": "",
  "version": "0.1.0",
  "scripts": {
    "generate": "npx prisma generate",
    "deploy": "npx prisma migrate deploy",
    "dev": "npm run generate && nodemon --watch \"src/**\" --ext \"js,json\" --exec \"node src/index.js\"",
    "build": "npm run generate",
    "start": "npm run build && node build/index.js"
  },
  "prisma": {
    "schema": "prisma/schema.prisma"
  },
  "dependencies": {
    "@prisma/client": "^3.6.0"
  },
  "devDependencies": {
    "@tsconfig/node16": "^1.0.2",
    "@types/node": "^16.11.12",
    "nodemon": "^2.0.15",
    "prisma": "^3.6.0"
  }
}

I run this in Kubernetes. To make things smooth with database and migrations I run an initContainer that runs the prisma migrate deploy.

apiVersion: apps/v1
kind: Deployment
metadata:
  name: EXAMPLE
spec:
  replicas: 1
  selector:
    matchLabels:
      app: EXAMPLE
  strategy:
    rollingUpdate:
      maxSurge: 100%
      maxUnavailable: 0
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: EXAMPLE
    spec:
      containers:
        image: DOCKER_IMAGE
        imagePullPolicy: IfNotPresent
        name: SERVICE_NAME
        ports:
        - containerPort: 8080
          name: http
          protocol: TCP
      initContainers:
      - command:
        - npm
        - run
        - deploy
        image: DOCKER_IMAGE
        imagePullPolicy: IfNotPresent
        name: database-migrate-deploy

(This is a live service I just copied and stripped away anything non essential)

I hope this could be of use to someone

🌐
Docker Hub
hub.docker.com › r › prismagraphql › prisma
prismagraphql/prisma - Docker Image
Learn how to get started with Prisma here⁠. The Docker CLI⁠ and Docker Compose CLI⁠ are used to manage the Prisma servers.
🌐
Prisma
v1.prisma.io › docs › 1.34 › get-started › 01-setting-up-prisma-new-database-JAVASCRIPT-a002
Prisma 1.34 - Set up Prisma with JavaScript
Goals On this page, you will learn how to: Install the Prisma CLI Set up Prisma using Docker Configure your Prisma API Generate the Prisma client Read...
🌐
Docker Hub
hub.docker.com › r › timothyjmiller › prisma-studio
timothyjmiller/prisma-studio - Docker Image
A docker container with the latest LTS of NodeJS and the @prisma/cli module introspects your postgres database to auto-generate a prisma schema in the form schema.prisma.
🌐
Awslaunchgoat
awslaunchgoat.com › docs › local-dev › prisma
Prisma Migration & Seed
January 14, 2026 - This command generates the Prisma client with the latest schema changes, ensuring that your TypeScript code on the host machine is in sync with the updated schema. Now, let's update the seeding script in prisma/seed.ts to add email values to our users: Note: If you don't want to seed data every ...
🌐
Goprisma
goprisma.org › docs › reference › deploy › docker
Deploy Via Docker – Prisma Client Go
If you want to optimize your docker images even further, learn how to use a multi-stage build. FROM golang:1.20 as build WORKDIR /workspace # add go modules lockfiles COPY go.mod go.sum ./ RUN go mod download # prefetch the binaries, so that they will be cached and not downloaded on each change RUN go run github.com/steebchen/prisma-client-go prefetch COPY . ./ # generate the Prisma Client Go client RUN go run github.com/steebchen/prisma-client-go generate # or, if you use go generate to run the generator, use the following line instead # RUN go generate ./... # build the binary with all dependencies RUN go build -o /app .
🌐
Medium
medium.com › @vadymchernykh › use-docker-to-dockerize-express-js-prisma-with-postgres-pgadmin-f0586becfab0
Use Docker to dockerize Express.js & Prisma with Postgres & PGAdmin
January 27, 2024 - So, in the “/app/node_modules” directory inside the container, Docker will use the contents of the “reddit-backend_node-modules” named volume. env_file — just a path to my .env file. Here you can see variables for Prisma connection.