Working Build to Non-working Build, OpenSSL & Platform Issues, Docker, Linux, Mac
I'm suddenly having issues with creating a new docker image of my nextjs with prisma app.
The issues relate to openssl and the wrong prisma binary being built for the wrong environment. I've now wasted half a day so far trying to resolve this issue.
What gets me the most though, is that I literally built this project about a week ago without issue and it is running in production. So why can I now not build the same Docker image at the same git ref?
It's so frustrating.
3 Replies
If anyone can offer any advice on how to resolve this issue, it would be much appreciated. I'm working on Mac, building for Linux. Dockerfile & docker-compose.yml to follow:
Here is my Dockerfile:
And my docker-compose.yml:
FWIW installing openssl at build does not solve the issue.
Nor does "Add "linux-musl" to
and updating my Dockerfile have resolved this issue.
Dockerfile:
33.60 prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
33.60 Please manually install OpenSSL and try installing Prisma again.
33.60 prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
33.60 Please manually install OpenSSL and try installing Prisma again.
33.61 Error [PrismaClientInitializationError]: Unable to require(`/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/libquery_engine-linux-musl.so.node`).
33.61 The Prisma engines do not seem to be compatible with your system. Please refer to the documentation about Prisma's system requirements: https://pris.ly/d/system-requirements
33.61
33.61 Details: Error loading shared library libssl.so.1.1: No such file or directory (needed by /app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/libquery_engine-linux-musl.so.node)
33.61 at Object.loadLibrary (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:111:10243)
33.61 at async _r.loadEngine (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:112:448)
33.61 at async _r.instantiateLibrary (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:111:12599) {
33.61 clientVersion: '5.22.0',
33.61 errorCode: undefined
33.61 }
33.60 prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
33.60 Please manually install OpenSSL and try installing Prisma again.
33.60 prisma:warn Prisma failed to detect the libssl/openssl version to use, and may not work as expected. Defaulting to "openssl-1.1.x".
33.60 Please manually install OpenSSL and try installing Prisma again.
33.61 Error [PrismaClientInitializationError]: Unable to require(`/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/libquery_engine-linux-musl.so.node`).
33.61 The Prisma engines do not seem to be compatible with your system. Please refer to the documentation about Prisma's system requirements: https://pris.ly/d/system-requirements
33.61
33.61 Details: Error loading shared library libssl.so.1.1: No such file or directory (needed by /app/node_modules/.pnpm/@[email protected][email protected]/node_modules/.prisma/client/libquery_engine-linux-musl.so.node)
33.61 at Object.loadLibrary (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:111:10243)
33.61 at async _r.loadEngine (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:112:448)
33.61 at async _r.instantiateLibrary (/app/node_modules/.pnpm/@[email protected][email protected]/node_modules/@prisma/client/runtime/library.js:111:12599) {
33.61 clientVersion: '5.22.0',
33.61 errorCode: undefined
33.61 }
FROM node:22-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Update CA certificates
#RUN apt-get update && apt-get install -y ca-certificates
# Install dependencies based on the preferred package manager
COPY package.json pnpm-lock.yaml ./
COPY ./prisma/schema.prisma ./prisma/schema.prisma
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
# Update CA certificates
#RUN apt-get update && apt-get install -y ca-certificates
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG DATABASE_URL=${DATABASE_URL}
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="0.0.0.0" node server.js
FROM node:22-alpine AS base
# Install dependencies only when needed
FROM base AS deps
RUN apk add --no-cache libc6-compat
WORKDIR /app
# Update CA certificates
#RUN apt-get update && apt-get install -y ca-certificates
# Install dependencies based on the preferred package manager
COPY package.json pnpm-lock.yaml ./
COPY ./prisma/schema.prisma ./prisma/schema.prisma
RUN \
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
elif [ -f package-lock.json ]; then npm ci; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm i --frozen-lockfile; \
else echo "Lockfile not found." && exit 1; \
fi
# Rebuild the source code only when needed
FROM base AS builder
WORKDIR /app
# Update CA certificates
#RUN apt-get update && apt-get install -y ca-certificates
COPY --from=deps /app/node_modules ./node_modules
COPY . .
ARG DATABASE_URL=${DATABASE_URL}
RUN \
if [ -f yarn.lock ]; then yarn run build; \
elif [ -f package-lock.json ]; then npm run build; \
elif [ -f pnpm-lock.yaml ]; then corepack enable pnpm && pnpm run build; \
else echo "Lockfile not found." && exit 1; \
fi
# Production image, copy all the files and run next
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
COPY --from=builder /app/public ./public
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# You only need to copy next.config.js if you are NOT using the default configuration
COPY --from=builder /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="0.0.0.0" node server.js
services:
app:
platform: linux/x86_64
build:
context: .
args:
DATABASE_URL: ${DATABASE_URL}
environment:
- DATABASE_URL=${DATABASE_URL}
ports:
- "3000:3000"
services:
app:
platform: linux/x86_64
build:
context: .
args:
DATABASE_URL: ${DATABASE_URL}
environment:
- DATABASE_URL=${DATABASE_URL}
ports:
- "3000:3000"
binaryTargets
in the "schema.prisma" file and run prisma generate
after saving it" ðŸ˜
A mixture of adding:
binaryTargets = ["native", "linux-musl"]
binaryTargets = ["native", "linux-musl"]
FROM node:22-alpine AS base
# Install dependencies required by Prisma and Node.js
RUN apk add --no-cache libc6-compat openssl git bash
WORKDIR /app
# Copy only schema.prisma for generating Prisma Client
COPY ./prisma ./prisma
# Install dependencies and generate Prisma Client
FROM base AS prisma
COPY package.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm install --frozen-lockfile
RUN npx prisma generate
# Build the application
FROM base AS builder
WORKDIR /app
COPY --from=prisma /app/node_modules ./node_modules
COPY . .
ARG DATABASE_URL=${DATABASE_URL}
RUN corepack enable pnpm && pnpm run build
# Prepare the runtime environment
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
# Add Node.js user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy build output and necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="0.0.0.0" node server.js
FROM node:22-alpine AS base
# Install dependencies required by Prisma and Node.js
RUN apk add --no-cache libc6-compat openssl git bash
WORKDIR /app
# Copy only schema.prisma for generating Prisma Client
COPY ./prisma ./prisma
# Install dependencies and generate Prisma Client
FROM base AS prisma
COPY package.json pnpm-lock.yaml ./
RUN corepack enable pnpm && pnpm install --frozen-lockfile
RUN npx prisma generate
# Build the application
FROM base AS builder
WORKDIR /app
COPY --from=prisma /app/node_modules ./node_modules
COPY . .
ARG DATABASE_URL=${DATABASE_URL}
RUN corepack enable pnpm && pnpm run build
# Prepare the runtime environment
FROM base AS runner
WORKDIR /app
ENV NODE_ENV production
ENV NEXT_TELEMETRY_DISABLED 1
# Add Node.js user
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nextjs
# Set the correct permission for prerender cache
RUN mkdir .next
RUN chown nextjs:nodejs .next
# Copy build output and necessary files
COPY --from=builder /app/public ./public
COPY --from=builder /app/next.config.js ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./
COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static
USER nextjs
EXPOSE 3000
ENV PORT 3000
CMD HOSTNAME="0.0.0.0" node server.js
Thank you for sharing your solution! This error was caused by a recent change in alpine version of node. Other users also faced the same issue. Using slim version of node usually fixed the issue for them.
Thanks for letting me know, it's appreciated.