Error relocating better_sqlite3.node: fcntl64: symbol not found when building Docker image

System Information
  • Strapi Version: 4.5.5
  • Operating System: linux
  • Database: sqlite
  • Node Version: 16
  • NPM Version: 8
  • Yarn Version: 1.22

Hi I’m trying to create a Docker image of Strapi. I copy-pasted the Dockerfile from Custom Docker Container - Strapi Developer Docs. I’m trying to use sqlite as I’m running Strapi in a resource-constrained environment and sqlite works fine. Unfortunately, when running the Docker image I get the following error at container boot:

$ npm install @vscode/sqlite3 --save
Error relocating /opt/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node: fcntl64: symbol not found
    at Client_BetterSQLite3.initializeDriver (/opt/app/node_modules/knex/lib/client.js:197:13)
    at new Client (/opt/app/node_modules/knex/lib/client.js:75:12)
    at new Client_SQLite3 (/opt/app/node_modules/knex/lib/dialects/sqlite3/index.js:22:5)
    at new Client_BetterSQLite3 (/opt/app/node_modules/knex/lib/dialects/better-sqlite3/index.js:5:1)
    at knex (/opt/app/node_modules/knex/lib/knex-builder/Knex.js:12:28)
    at createConnection (/opt/app/node_modules/@strapi/database/lib/connection.js:55:24)
    at new Database (/opt/app/node_modules/@strapi/database/lib/index.js:32:23)
    at Function.Database.init (/opt/app/node_modules/@strapi/database/lib/index.js:79:35)
    at Strapi.bootstrap (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:411:30)
    at Strapi.load (/opt/app/node_modules/@strapi/strapi/lib/Strapi.js:478:16)
error Command failed with exit code 1.
info Visit for documentation about this command.

Why? How to fix? Thanks

Edit: I tried with debian bullseye and it works, but it would be nice to have it working with Alpine since the image is much smaller.

1 Like

Whats the Dockerfile you are using ?
Also if you are make sure you bind-mount the file when you run it else you will loose all your data

Have you found the solution to this problem? I am facing the same issue

Same issue here, I tried with different node images like node:18.14-bullseye, node:16-slim and node:16-alpine.

dm-cms@0.1.0 develop
> strapi develop

Starting the compilation for TypeScript files in /opt/app
Knex: run
$ npm install @vscode/sqlite3 --save
Error relocating /opt/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node: fcntl64: symbol not found
Error: Error relocating /opt/app/node_modules/better-sqlite3/build/Release/better_sqlite3.node: fcntl64: symbol not found
    at Module._extensions..node (node:internal/modules/cjs/loader:1310:18)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
    at Module._load (node:internal/modules/cjs/loader:930:12)
    at Module.require (node:internal/modules/cjs/loader:1113:19)
    at require (node:internal/modules/cjs/helpers:103:18)
    at bindings (/opt/app/node_modules/bindings/bindings.js:112:48)
    at Object.<anonymous> (/opt/app/node_modules/better-sqlite3/lib/database.js:9:24)
    at Module._compile (node:internal/modules/cjs/loader:1226:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1280:10)
    at Module.load (node:internal/modules/cjs/loader:1089:32)
[2023-02-15 13:16:14.934] debug: ⛔️ Server wasn't able to start properly.
[2023-02-15 13:16:14.935] error: Knex: run

Since this was asked and nobody answered this would go for you as well

Hey @Eventyret

I’m using the Dockerfile examples from the documentation.

FROM node:16-alpine
# Installing libvips-dev for sharp Compatibility
RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
ARG NODE_ENV=development
COPY ./package.json ./yarn.lock ./
ENV PATH /opt/node_modules/.bin:$PATH
RUN yarn config set network-timeout 600000 -g && yarn install
WORKDIR /opt/app
COPY ./ .
RUN yarn build
CMD ["yarn", "develop"]

Build is passing correctly, this error happens on the deployment stage.

Build log
---> 07ea0116a210
Step 2/13 : RUN apk update && apk add --no-cache build-base gcc autoconf automake zlib-dev libpng-dev nasm bash vips-dev
 ---> Using cache
 ---> 72217b4972e4
Step 3/13 : ARG NODE_ENV=development
 ---> Using cache
---> dc043605f46f
Step 4/13 : ENV NODE_ENV=${NODE_ENV}
 ---> Using cache
 ---> 192c9be64253
Step 5/13 : WORKDIR /opt/
 ---> Using cache
 ---> 7c62f69390ec
Step 6/13 : COPY ./package.json ./package-lock.json ./
 ---> Using cache
 ---> 58bd77289d20
217Step 7/13 : ENV PATH /opt/node_modules/.bin:$PATH
 ---> Using cache
 ---> fa34e77cff80
Step 8/13 : RUN npm install
 ---> Using cache
 ---> 8f98f2008069
Step 9/13 : WORKDIR /opt/app
 ---> Using cache
 ---> b3bc7aff45ee
Step 10/13 : COPY ./ .
 ---> fa9273f0a7ed
Step 11/13 : RUN npm run build
---> Running in 007579baf68f
> dm-cms@0.1.0 build
> strapi build
Starting the compilation for TypeScript files in /opt/app
Building your admin UI with development configuration...
ℹ Compiling Webpack
✔ Webpack: Compiled successfully in 26.10s
Admin UI built successfully
Removing intermediate container 007579baf68f
 ---> aabecdff7210
Step 12/13 : EXPOSE 1337
 ---> Running in 4f4532d505a9
Removing intermediate container 4f4532d505a9
 ---> 8276016df4e8
Step 13/13 : CMD ["npm", "run", "develop"]
 ---> Running in 42184d53daae
Removing intermediate container 42184d53daae
 ---> f9a11ab14
Successfully built f9247a11ab14

@Boegie19 @DMehaffy
This the bug you talked about with the versions?

Dockerfile looks correct :slightly_smiling_face:
Is this hosted on a VPS or where is it hosted?

Not sure if the question was directed at me but I will answer.

This is inside a CI/CD(Gitlab) using K8s then will be deployed to GCP.

Sorry yes it was.
What version of Strapi are you using?


Strapi 4.6.1

Container configuration
- name: strapi
          image: ${NODE_IMAGE}
            - name: PORT
              value: "1337"
            - name: HOST
              value: ""
            - name: APP_KEYS
              value: ${APP_KEYS}
            - name: API_TOKEN_SALT
              value: ${API_TOKEN_SALT}
            - name: ADMIN_JWT_SECRET
              value: ${ADMIN_JWT_SECRET}
            - name: JWT_SECRET
              value: ${JWT_SECRET}
            - containerPort: 1337
              protocol: TCP
          imagePullPolicy: Always
            - name: shared-data
              mountPath: /opt/app
          command: [sh, -c]
          args: ["cd /opt/app && npm run develop"]

any solutions to this? I just started to play around with strapi and docker and used the Dockerfile from the documentation and I am facing the same problem.
I am building it in WSL2 and it is building fine, without errors.

I think I “fixed” it, I was missing a .dockerignore file, the file has following contents:


now after the rebuild, it seems to work. :slight_smile: