Skip to content

Prisma inside docker takes almost 300mb #11577

Closed

Description

@nikolasburk

Converted the Discussion into an issue based on this internal convo.

Discussed in #11572

Originally posted by vertti February 2, 2022
I was digging through my docker container that contains a simple app that uses Prisma.

Under node_modules you can see Prisma taking space like this:
Screenshot 2022-02-02 at 17 06 03

total of 127MB. But slightly surprisingly, another 114 MB of Prisma stuff is found under .cache:
Screenshot 2022-02-02 at 17 06 45

Are the .cache files necessary? Can I somehow avoid pulling those in? The total added size of Prisma is quite a lot!

Activity

  1. Jolg42 commented on Feb 2, 2022

    @Jolg42
    Contributor

    The .cache directory is used for downloading the binaries by the @prisma/engines npm package, the code lives here https://github.com/prisma/engines-wrapper

    I don't think we documented that .cache directory anywhere, so let's first do an internal documentation of what it is and how it works before we change it.

  2. jsardev commented on Sep 19, 2022

    @jsardev

    Any updates on this? I think things got even worse since this report, as having just the @prisma/client in dependencies ends up adding ~250mb of size:

    $ du -d 1 -h node_modules/ | grep prisma
    118.1M	node_modules/@prisma
    40.0M	node_modules/.prisma
    93.8M	node_modules/prisma
    

    And that's apart from the .cache, which adds additional ~153mb:

    $ du -d 1 -h ~/.cache/ | grep prisma
    153.0M	/root/.cache/prisma
    

    Dockerizing an app using prisma (just the client) increases the image size by a total of ~400mb 😭

  3. JardarTemalogic commented on Dec 8, 2022

    @JardarTemalogic

    I did some work to reduce the size of prisma in production. The build is intended for Linux. And a Docerfile that works for me is:

    RUN rm -rf node_modules/.cache/
    RUN rm -rf node_modules/@prisma/engines/
    RUN rm -rf node_modules/.prisma/client/query_engine-windows.dll.node
    RUN rm -rf node_modules/prisma/
    

    This results in a total size of 44MB:

    41M     .prisma
    2.9M    @prisma
    

    The build only queries the database and I do not use migration in production.

  4. janpio commented on Dec 20, 2022

    @janpio
    Contributor

    (In our release 4.8.0 we have made significant improvements, average decrease of 50%, on the size of our engine files. That should ease the pain, but we will continue looking into other solutions of course. Expect more updates from us in this direction soon.)

  5. removed their assignment
    on Dec 21, 2022
  6. mildronize commented on Dec 24, 2022

    @mildronize

    I use Prisma 4.8.0 and remove unused files from this issue, finally i've got 17 MB of Prisma library ( from my blog post: https://thadaw.com/s/c2tcmvl/ (Note: sorry I'm writing in Thai))

    image

    ###################
    # BUILD FOR PRODUCTION
    ###################
    
    FROM node:18 As build
    RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
    
    WORKDIR /app
    
    COPY --chown=node:node . .
    
    RUN pnpm install --frozen-lockfile
    
    RUN pnpx nx run remote-state-server:build-esbuild
    
    USER node
    
    ###################
    # PRODUCTION
    ###################
    
    # Not Natively support ARM64 (M1)
    FROM alpine:3.17 As production
    
    ENV PORT=3333
    ENV NODE_VERSION 18.12.1-r0
    ENV NPM_VERSION 9.1.2-r0
    ENV OPENSSL_COMPAT_VERSION 1.1.1s-r0
    
    WORKDIR /app
    COPY --chown=node:node package.json .
    COPY --chown=node:node apps/remote-state-server/prisma ./prisma/
    COPY --chown=node:node --from=build /app/dist/apps/remote-state-server .
    
    RUN apk add --update --no-cache nodejs=$NODE_VERSION
    
    RUN apk add --update --no-cache \
      # For getting node-prune
      curl \
      # For Prisma client in Alpine
      # Fix "Error: Unable to establish a connection to query-engine-node-api library. It seems there is a problem with your OpenSSL installation!"
      # Ref: https://github.com/prisma/prisma/issues/14073
      openssl1.1-compat=$OPENSSL_COMPAT_VERSION \
      npm=$NPM_VERSION \
      # npx will look the local node_modules first, if not it will install globally
      # Ref: https://stackoverflow.com/questions/22420564/install-only-one-package-from-package-json
      && PRISMA_CLIENT_VERSION=$(node -pe "require('./package').dependencies['@prisma/client']") \
      && PRISMA_VERSION=$(node -pe "require('./package').dependencies['prisma']") \
      # We don't need package.json anymore
      && rm -rf package.json \
      && npm install @prisma/client@$PRISMA_CLIENT_VERSION \
      && npm install -D prisma@$PRISMA_VERSION \
      # We don't have the existing sqlite file
      # So, we will create a fresh sqlite every time when build
      # This migration should be run every time when build
      && npx prisma migrate deploy \
      # Prepare prisma library
      # If we don't have package.json, prisma will create for you, and create a local node_modules
      && npx prisma generate \
      # Prune non-used files
      && npm prune --production \
      # Clean Prisma non-used files https://github.com/prisma/prisma/issues/11577
      && rm -rf node_modules/.cache/ \
      && rm -rf node_modules/@prisma/engines/ \
      && rm -rf node_modules/@prisma/engines-version \
      && rm -rf node_modules/prisma \
      # Remove cache
      && rm -rf /root/.cache/ \
      && rm -rf /root/.npm/ \
      # Remove all unused dependecies
      && apk del openssl1.1-compat npm curl
    
    EXPOSE ${PORT}
    
    # Create a group and user
    RUN addgroup -g 1000 node \
        && adduser -u 1000 -G node -s /bin/sh -D node
    
    USER node
    
    CMD [ "node", "main.js" ]
  7. added a commit that references this issue on Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions