create-t3-app: bug: docs - Docker node:16-alpine requires setting `engineType = "binary"` for Prisma to work

Provide environment information

System: OS: Linux 6.0 Fedora Linux 37 (Workstation Edition) CPU: (16) x64 AMD Ryzen 7 PRO 6850U with Radeon Graphics Memory: 23.97 GB / 30.12 GB Container: Yes Shell: 5.9 - /bin/zsh Binaries: Node: 16.19.0 - ~/.volta/tools/image/node/16.19.0/bin/node npm: 8.19.3 - ~/.volta/tools/image/node/16.19.0/bin/npm

ct3aMetadata.initVersion: 6.11.3

Describe the bug

I’ve added a Dockerfile (copy-pasted from the docs, using node:16-alpine as a base image) and docker-compose.yml to a freshly bootstrapped app. I modified index.tsx to run trpc.example.getAll.useQuery(), and received this error message at runtime:

Listening on port 3000 url: http://localhost:3000
prisma:error
Invalid `prisma.example.findMany()` invocation:


Unable to load Node-API Library from /app/node_modules/.prisma/client/libquery_engine-linux-musl.so.node, Library may be corrupt
  • I got a similar error with node:16-buster-slim (pointing to the Debian engine).
  • Changing the base image to node:16-buster fixes the error.
  • Adding engineType = "binary" to Prisma generator client also fixes the error under node:16-alpine.

To reproduce

  • Bootstrap application with trpc and prisma:
npm create t3-app@6.11.3
  • Follow steps 1-3 from the docs
  • Add trpc.example.getAll.useQuery() to index.tsx
  • Use the following minimal docker-compose.yml:
version: "3.9"
services:
  app:
    platform: "linux/amd64"
    build:
      context: .
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_CLIENTVAR: "clientvar"
    working_dir: /app
    ports:
      - "3000:3000"
    image: t3-app
    environment:
      - DATABASE_URL=mysql://foo:password@db:3306/bar
  db:
    image: mysql:8
    command: --default-authentication-plugin=mysql_native_password
    restart: always
    ports:
      - 3306:3306
    environment:
      MYSQL_USER: foo
      MYSQL_PASSWORD: password
      MYSQL_DATABASE: bar
      MYSQL_RANDOM_ROOT_PASSWORD: true
    volumes:
      - db:/var/lib/mysql

volumes:
  db: {}
  • Run docker compose up -d --build
  • Visit localhost:3000, then check the logs

Additional information

It’s worth noting that setting engineType = "binary" is not a recommended approach according to the Prisma docs as it introduces additional overhead in the architecture: Query Engine. If there’s a problem with using the Node-API Library in Alpine that seems out of scope for the t3 docs, but might be worth mentioning.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 26 (21 by maintainers)

Commits related to this issue

Most upvoted comments

@nicolomaioli hi, how can I set openssl over openssl1.1-compat ? I have tried node:16-alpine3.16 without success

Change this line in the Dockerfile:

- RUN apk add --no-cache libc6-compat openssl1.1-compat
+ RUN apk add --no-cache libc6-compat openssl

Edit: I believe Alpine 3.17 uses v3 of openssl, which is why you need to specify 1.1. The -compat I think has to do with the fact that Alpine uses musl rather than glibc. Hopefully this helps!

@nicolomaioli Certo! Feel free to reach out again opening a new Prisma issue, although I think I know why it didn’t work initially with alpine:3.17. Prisma depends on some Rust engines which are compiled for specific operating systems and/or openssl versions. As you can see in our docs, we only started supporting openssl-3.0.x for Linux Alpine starting from prisma@4.8.0, which we released right before Christmas 2022. You have probably opened this issue just a few days before that

That’s brilliant, thank you! I’ll try the different engines should be pretty straightforward. And thanks for reaching out! 🙏

No worries! That all sounds good. I’ll take Node 18 Alpine 3.17 for a spin and if everything seems to work well I’ll get a PR going in the next few days.

I think last time it seemed to work well with updating the code and the English docs leaving the translations untouched, as I will be removing some of the outdated notes. Let me know if that all sounds good with you 😃

Sounds good 😃

Btw I got a full setup working great on node 18 / alpine 3.17 including next-auth, see here: https://github.com/t3-oss/create-t3-app/issues/992#issuecomment-1404043116 I based it on an upcoming change to the env schema validation, so maybe makes sense to get that merged before - my implementation of getting next-auth in GSSP to not crash the build by branching in the env.mjs file is a bit sloppy.

Still haven’t had time to work on creating a good docker dev setup. With the setup above you can run the app non-dockerized in dev without having to change any files, but I know many projects might want their T3 app to be part of a multi-container setup because that’s what they’re already on, docker internal networking, etc.

@jkomyno thanks for coming in here and clarifying 😃

@nicolomaioli we are already on Prisma 4.8.0 now so this should hopefully be an easy fix now. If it works for you, would you be up for opening a pr for it?

Happy to 🙌

@nicolomaioli Certo! Feel free to reach out again opening a new Prisma issue, although I think I know why it didn’t work initially with alpine:3.17. Prisma depends on some Rust engines which are compiled for specific operating systems and/or openssl versions. As you can see in our docs, we only started supporting openssl-3.0.x for Linux Alpine starting from prisma@4.8.0, which we released right before Christmas 2022. You have probably opened this issue just a few days before that

Hi, I’m one of the Prisma maintainers. I second what @nicolomaioli has stated here. Please read this comment in a Prisma issue if you’re interested in why this issue happened and how to truly solve it

Change this line in the Dockerfile:

- RUN apk add --no-cache libc6-compat openssl1.1-compat
+ RUN apk add --no-cache libc6-compat openssl

Edit: I believe Alpine 3.17 uses v3 of openssl, which is why you need to specify 1.1. The -compat I think has to do with the fact that Alpine uses musl rather than glibc. Hopefully this helps!

Thank you @nicolomaioli , it works! Using node:16-alpine3.16 and openssl