'Error relocating /usr/src/api/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node: fcntl64: symbol not found?

I have a container running an API that works great. A few days ago I had some problems with my application so I decided to go back and rebuild my Docker container. But everything didn't go as planned... When I restarted with a new rebuilt version I got a sqlite3 error:

api_1  | > node src/index.js
api_1  | 
api_1  | internal/modules/cjs/loader.js:1131
api_1  |   return process.dlopen(module, path.toNamespacedPath(filename));
api_1  |                  ^
api_1  | 
api_1  | Error: Error relocating /usr/src/api/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node: fcntl64: symbol not found
api_1  |     at Object.Module._extensions..node (internal/modules/cjs/loader.js:1131:18)
api_1  |     at Module.load (internal/modules/cjs/loader.js:937:32)
api_1  |     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
api_1  |     at Module.require (internal/modules/cjs/loader.js:961:19)
api_1  |     at require (internal/modules/cjs/helpers.js:92:18)
api_1  |     at Object.<anonymous> (/usr/src/api/node_modules/sqlite3/lib/sqlite3-binding.js:4:15)
api_1  |     at Module._compile (internal/modules/cjs/loader.js:1072:14)
api_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
api_1  |     at Module.load (internal/modules/cjs/loader.js:937:32)
api_1  |     at Function.Module._load (internal/modules/cjs/loader.js:778:12)
FROM node:14.17.6-alpine

# Create the directory!
RUN mkdir -p /usr/src/api
WORKDIR /usr/src/api

# Copy and Install our api
COPY package.json /usr/src/api
RUN npm install

# Our precious api
COPY . /usr/src/api
RUN ln -snf /usr/share/zoneinfo/Europe/Paris /etc/localtime && echo Europe/Paris > /etc/timezone

# Start me!
CMD ["npm", "start"]

I managed to find the version that has the same source code but it works fine. So I try to solve the problem for my next build: Here are the execution traces of the two versions with the same source code.

The execution traces of the build that works:

$ docker build -t $CONTAINER_IMAGE:$CI_COMMIT_SHA ./$PATH_DOCKERFILE
Step 1/8 : FROM node:14.17.6-alpine
14.17.6-alpine: Pulling from library/node
6a428f9f83b0: Pulling fs layer
630852b09df4: Pulling fs layer
f13ad23a48a4: Pulling fs layer
43df7c393f3d: Pulling fs layer
43df7c393f3d: Waiting
6a428f9f83b0: Verifying Checksum
6a428f9f83b0: Download complete
f13ad23a48a4: Verifying Checksum
f13ad23a48a4: Download complete
43df7c393f3d: Verifying Checksum
43df7c393f3d: Download complete
6a428f9f83b0: Pull complete
630852b09df4: Verifying Checksum
630852b09df4: Download complete
630852b09df4: Pull complete
f13ad23a48a4: Pull complete
43df7c393f3d: Pull complete
Digest: sha256:8c94a0291133e16b92be5c667e0bc35930940dfa7be544fb142e25f8e4510a45
Status: Downloaded newer image for node:14.17.6-alpine
 ---> 1d909dafa77f
Step 2/8 : RUN mkdir -p /usr/src/api
 ---> Running in d1dc77ffefaf
Removing intermediate container d1dc77ffefaf
 ---> d00d0ca95030
Step 3/8 : WORKDIR /usr/src/api
 ---> Running in 01661be5464e
Removing intermediate container 01661be5464e
 ---> 977f95e8b0fe
Step 4/8 : COPY package.json /usr/src/api
 ---> 61734ae0ce22
Step 5/8 : RUN npm install
 ---> Running in 268fb41d9940
npm WARN deprecated [email protected]: Please upgrade to @mapbox/node-pre-gyp: the non-scoped node-pre-gyp package is deprecated and only the @mapbox scoped package will recieve updates in the future
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
npm WARN deprecated [email protected]: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
> [email protected] install /usr/src/api/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
node-pre-gyp WARN Using request for node-pre-gyp https download 
[sqlite3] Success: "/usr/src/api/node_modules/sqlite3/lib/binding/napi-v3-linux-x64/node_sqlite3.node" is installed via remote
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
added 169 packages from 202 contributors and audited 169 packages in 18.574s
4 packages are looking for funding
  run `npm fund` for details
found 5 high severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 268fb41d9940
 ---> 9a56f37f5ea0
Step 6/8 : COPY . /usr/src/api
 ---> e87d419c4d57
Step 7/8 : RUN ln -snf /usr/share/zoneinfo/Europe/Paris /etc/localtime && echo Europe/Paris > /etc/timezone
 ---> Running in 003be13bd790
Removing intermediate container 003be13bd790
 ---> 2735e5435222
Step 8/8 : CMD ["npm", "start"]
 ---> Running in 7315e9692e2e
Removing intermediate container 7315e9692e2e
 ---> bb1800cf2b98
Successfully built bb1800cf2b98

The traces of execution of the build that does not work:

$ docker build -t $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME .
Step 1/8 : FROM node:14.17.6-alpine
14.17.6-alpine: Pulling from library/node
6a428f9f83b0: Pulling fs layer
630852b09df4: Pulling fs layer
f13ad23a48a4: Pulling fs layer
43df7c393f3d: Pulling fs layer
43df7c393f3d: Waiting
6a428f9f83b0: Verifying Checksum
6a428f9f83b0: Download complete
f13ad23a48a4: Verifying Checksum
f13ad23a48a4: Download complete
43df7c393f3d: Verifying Checksum
43df7c393f3d: Download complete
6a428f9f83b0: Pull complete
630852b09df4: Download complete
630852b09df4: Pull complete
f13ad23a48a4: Pull complete
43df7c393f3d: Pull complete
Digest: sha256:8c94a0291133e16b92be5c667e0bc35930940dfa7be544fb142e25f8e4510a45
Status: Downloaded newer image for node:14.17.6-alpine
 ---> 1d909dafa77f
Step 2/8 : RUN mkdir -p /usr/src/api
 ---> Running in c9a3c82cf360
Removing intermediate container c9a3c82cf360
 ---> 3f3b5ec7912b
Step 3/8 : WORKDIR /usr/src/api
 ---> Running in 56b15384366c
Removing intermediate container 56b15384366c
 ---> 221dcba87eb5
Step 4/8 : COPY package.json /usr/src/api
 ---> 0f369984e965
Step 5/8 : RUN npm install
 ---> Running in c77ef8c0f496
> [email protected] install /usr/src/api/node_modules/sqlite3
> node-pre-gyp install --fallback-to-build
[sqlite3] Success: "/usr/src/api/node_modules/sqlite3/lib/binding/napi-v6-linux-x64/node_sqlite3.node" is installed via remote
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] No description
added 159 packages from 175 contributors and audited 159 packages in 17.298s
6 packages are looking for funding
  run `npm fund` for details
found 0 vulnerabilities
Removing intermediate container c77ef8c0f496
 ---> ccb19de751c9
Step 6/8 : COPY . /usr/src/api
 ---> d43249d2c30a
Step 7/8 : RUN ln -snf /usr/share/zoneinfo/Europe/Paris /etc/localtime && echo Europe/Paris > /etc/timezone
 ---> Running in b0991e5edfd6
Removing intermediate container b0991e5edfd6
 ---> 352c6a3611fd
Step 8/8 : CMD ["npm", "start"]
 ---> Running in 9d878994fc42
Removing intermediate container 9d878994fc42
 ---> 0adaf22448f1
Successfully built 0adaf22448f1


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source