You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Docker-compose启动时Prisma OpenSSL版本检测失败问题求助

问题:Docker环境中Prisma无法检测OpenSSL版本并解析Schema引擎响应

本地启动Docker实例时,执行docker-compose up后出现两个核心错误:

  1. Prisma无法检测libssl/OpenSSL版本,默认使用"openssl-1.1.x"
  2. 无法解析Schema引擎响应的JSON(SyntaxError: Unexpected token 'E', "Error load"... is not valid JSON)

已尝试的修复操作:

  • brew install openssl@3
  • rm -rf node_modules && npm i
  • npx prisma generate
  • npx prisma migrate --dev

错误日志

> 2024-12-10 12:46:12 > laredo-backend-api@0.0.1 start:docker:dev
> 2024-12-10 12:46:12 > npm install && npm run start:prisma && npm run
> start:dev 2024-12-10 12:46:12  2024-12-10 12:46:16  2024-12-10
> 12:46:16 added 1 package, and audited 1011 packages in 3s 2024-12-10
> 12:46:16  2024-12-10 12:46:16 134 packages are looking for funding
> 2024-12-10 12:46:16   run `npm fund` for details 2024-12-10 12:46:16 
> 2024-12-10 12:46:16 6 vulnerabilities (1 low, 2 moderate, 3 high)
> 2024-12-10 12:46:16  2024-12-10 12:46:16 To address issues that do not
> require attention, run: 2024-12-10 12:46:16   npm audit fix 2024-12-10
> 12:46:16  2024-12-10 12:46:16 To address all issues, run: 2024-12-10
> 12:46:16   npm audit fix --force 2024-12-10 12:46:16  2024-12-10
> 12:46:16 Run `npm audit` for details. 2024-12-10 12:46:16  2024-12-10
> 12:46:16 > laredo-backend-api@0.0.1 start:prisma 2024-12-10 12:46:16 >
> prisma migrate deploy 2024-12-10 12:46:16  2024-12-10 12:46:22
> Environment variables loaded from .env 2024-12-10 12:46:22 Prisma
> schema loaded from prisma/schema.prisma 2024-12-10 12:46:22 Datasource
> "db": PostgreSQL database "laredo", schema "public" at "postgres:5432"
> 2024-12-10 12:46:22  2024-12-10 12:46:17 prisma:warn Prisma failed to
> detect the libssl/openssl version to use, and may not work as
> expected. Defaulting to "openssl-1.1.x". 2024-12-10 12:46:17 Please
> manually install OpenSSL and try installing Prisma again. 2024-12-10
> 12:46:22 prisma:warn Prisma failed to detect the libssl/openssl
> version to use, and may not work as expected. Defaulting to
> "openssl-1.1.x". 2024-12-10 12:46:22 Please manually install OpenSSL
> and try installing Prisma again. 2024-12-10 12:46:22 Error: Could not
> parse schema engine response: SyntaxError: Unexpected token 'E',
> "Error load"... is not valid JSON 2024-12-10 12:46:22 npm notice
> 2024-12-10 12:46:22 npm notice New minor version of npm available!
> 10.8.2 -> 10.9.2 2024-12-10 12:46:22 npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.9.2 2024-12-10 12:46:22
> npm notice To update run: npm install -g npm@10.9.2 2024-12-10
> 12:46:22 npm notice

现有配置

Prisma Generator配置

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "linux-musl", "darwin-arm64", "linux-musl-openssl-3.0.x"]
}

Dockerfile

FROM node:20-alpine AS builder

USER root

RUN npm i -g npm@~9.3.1

WORKDIR /usr/app

COPY . ./

RUN chmod +x ./entrypoint.sh

RUN npm ci

RUN npm run build

FROM node:20-alpine AS deployment

# added this to try to fix but still broken

RUN set -ex; \
    apk update; \
    apk add --no-cache \
    openssl

COPY --from=builder --chown=node:node /usr/app /usr/app

USER node

CMD ["sh"]

解决建议

  1. 调整Dockerfile中OpenSSL的安装与环境变量
    Alpine默认的openssl包版本不匹配,建议安装openssl3并指定Prisma的环境变量:
    修改deployment阶段的命令:

    RUN set -ex; \
        apk update; \
        apk add --no-cache openssl3; \
        ln -s /usr/lib/libssl3.so /usr/lib/libssl.so; \
        ln -s /usr/lib/libcrypto3.so /usr/lib/libcrypto.so
    ENV PRISMA_OPENSSL_VERSION="openssl-3.0.x"
    

    通过软链接让系统库路径匹配Prisma的预期,同时直接指定OpenSSL版本。

  2. 在Builder阶段生成适配Alpine的Prisma二进制文件
    当前Builder阶段生成的Prisma客户端可能不兼容目标环境,添加以下命令到Builder阶段:

    RUN npx prisma generate --binary-targets "linux-musl-openssl-3.0.x"
    

    确保生成的引擎适配Alpine+OpenSSL3环境。

  3. 彻底清理并重新构建镜像
    执行命令清理旧缓存和镜像,避免残留问题:

    docker-compose down -v
    docker rmi $(docker images -q)
    docker-compose build --no-cache
    docker-compose up
    
  4. 升级Prisma到最新稳定版
    版本不兼容是常见诱因,升级到最新版确保与OpenSSL3、Node.js20适配:

    npm install prisma@latest @prisma/client@latest
    

内容的提问来源于stack exchange,提问作者codernoob8

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.15 17:04:58