Express Sharp install via Docker issue

Tags: , , , ,



I need to use sharp. Its work fine on my workspace but if I deploymeny via docker then I get error. I am implementation all steps.

Error: 'linux-x64' binaries cannot be used on the 'linuxmusl-x64' platform. Please remove the 'node_modules/sharp' directory and run 'npm install' on the 'linuxmusl-x64' platform.

I think sharp is prebuilt when first install. It uses the architecture of my computer(darwin, arm) But when it runs on the docker, although it gets built again, the work talks about the architecture of my computer.

I tried remove node_modules folder on my workspaces. – yarn pm2 not found npm install on docker running. – permission problems

My Dockerfile:

FROM node:alpine

RUN mkdir -p /usr/src/node-app && chown -R node:node /usr/src/node-app

WORKDIR /usr/src/node-app

COPY package.json yarn.lock ./

USER node

RUN npm install --pure-lockfile
RUN npm install sharp --ignore-scripts=false

COPY --chown=node:node . .

EXPOSE 3050

My .dockerignore.

node_modules
**/node_modules
npm-debug.log
Dockerfile
.dockerignore
.git
.gitignore

docker build . When I do it, I see that sharp for my server is loaded among the docker logs.

found 11 vulnerabilities (6 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container e5ad8008eebd
 ---> 906e268b6fc3
Step 7/9 : RUN npm install sharp --ignore-scripts=false
 ---> Running in 933338813b5d

> sharp@0.27.0 install /usr/src/node-app/node_modules/sharp
> (node install/libvips && node install/dll-copy && prebuild-install) || (node-gyp rebuild && node install/dll-copy)

info sharp Using cached /home/node/.npm/_libvips/libvips-8.10.5-linuxmusl-x64.tar.br
npm WARN @apidevtools/swagger-parser@10.0.2 requires a peer of openapi-types@>=7 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.19.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.1 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.1: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ sharp@0.27.0
updated 1 package and audited 1348 packages in 20.689s

84 packages are looking for funding
  run `npm fund` for details

found 11 vulnerabilities (6 moderate, 5 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Removing intermediate container 933338813b5d
 ---> 838713a4cebb
Step 8/9 : COPY --chown=node:node . .
 ---> eb755fc2589e
Step 9/9 : EXPOSE 3050
 ---> Running in bf0a5c9e96c6
Removing intermediate container bf0a5c9e96c6
 ---> 347f113598fd
Successfully built 347f113598fd

My Docker-compose up log

mongodb_1   | 2021-01-09T19:31:15.802+0000 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=a8281f9d01ef
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] db version v4.2.1
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] allocator: tcmalloc
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] modules: none
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] build environment:
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten]     distmod: ubuntu1804
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten]     distarch: x86_64
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten]     target_arch: x86_64
mongodb_1   | 2021-01-09T19:31:15.815+0000 I  CONTROL  [initandlisten] options: { net: { bindIp: "0.0.0.0", port: 27017 }, security: { authorization: "enabled" }, storage: { dbPath: "/data/db" } }
mongodb_1   | 2021-01-09T19:31:15.816+0000 I  STORAGE  [initandlisten] Detected data files in /data/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
mongodb_1   | 2021-01-09T19:31:15.816+0000 I  STORAGE  [initandlisten] 
mongodb_1   | 2021-01-09T19:31:15.816+0000 I  STORAGE  [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
mongodb_1   | 2021-01-09T19:31:15.816+0000 I  STORAGE  [initandlisten] **          See http://dochub.mongodb.org/core/prodnotes-filesystem
mongodb_1   | 2021-01-09T19:31:15.816+0000 I  STORAGE  [initandlisten] wiredtiger_open config: create,cache_size=457M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
mongodb_1   | 2021-01-09T19:31:17.154+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:154424][1:0x7f96e9f8db00], txn-recover: Recovering log 194 through 195
api_node-app_1 exited with code 0
mongodb_1   | 2021-01-09T19:31:17.389+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:389583][1:0x7f96e9f8db00], txn-recover: Recovering log 195 through 195
mongodb_1   | 2021-01-09T19:31:17.527+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:527496][1:0x7f96e9f8db00], txn-recover: Main recovery loop: starting at 194/6016 to 195/256
mongodb_1   | 2021-01-09T19:31:17.643+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:643739][1:0x7f96e9f8db00], txn-recover: Recovering log 194 through 195
mongodb_1   | 2021-01-09T19:31:17.722+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:722144][1:0x7f96e9f8db00], txn-recover: Recovering log 195 through 195
mongodb_1   | 2021-01-09T19:31:17.784+0000 I  STORAGE  [initandlisten] WiredTiger message [1610220677:784868][1:0x7f96e9f8db00], txn-recover: Set global recovery timestamp: (0,0)
mongodb_1   | 2021-01-09T19:31:17.812+0000 I  RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0)
mongodb_1   | 2021-01-09T19:31:17.825+0000 I  STORAGE  [initandlisten] Timestamp monitor starting
mongodb_1   | 2021-01-09T19:31:17.827+0000 I  CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
mongodb_1   | 2021-01-09T19:31:17.828+0000 I  CONTROL  [initandlisten] 
mongodb_1   | 2021-01-09T19:31:17.844+0000 I  SHARDING [initandlisten] Marking collection local.system.replset as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:17.847+0000 I  STORAGE  [initandlisten] Flow Control is enabled on this deployment.
mongodb_1   | 2021-01-09T19:31:17.848+0000 I  SHARDING [initandlisten] Marking collection admin.system.roles as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:17.849+0000 I  SHARDING [initandlisten] Marking collection admin.system.version as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:17.850+0000 I  SHARDING [initandlisten] Marking collection local.startup_log as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:17.851+0000 I  FTDC     [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
mongodb_1   | 2021-01-09T19:31:17.855+0000 I  SHARDING [LogicalSessionCacheRefresh] Marking collection config.system.sessions as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:17.856+0000 I  NETWORK  [initandlisten] Listening on /tmp/mongodb-27017.sock
mongodb_1   | 2021-01-09T19:31:17.857+0000 I  NETWORK  [initandlisten] Listening on 0.0.0.0
mongodb_1   | 2021-01-09T19:31:17.857+0000 I  NETWORK  [initandlisten] waiting for connections on port 27017
mongodb_1   | 2021-01-09T19:31:17.858+0000 I  SHARDING [LogicalSessionCacheReap] Marking collection config.transactions as collection version: <unsharded>
mongodb_1   | 2021-01-09T19:31:18.004+0000 I  SHARDING [ftdc] Marking collection local.oplog.rs as collection version: <unsharded>

I think, I need to install sharp on docker for pre-built proccess. I didn’t understand how docker works very well. it has to do with my amateurishness that I live with.

Relation Issue : linux-x64 binaries cannot be used on the linuxmusl-x64 platform error

Answer

Alpine uses musl for its C library. You can either use a different non-alpine based image such as node:12-buster-slim or any of the other non-Alpine tags here, or try to get it to work by setting up glibc with the instructions here. Using a Debian or Ubuntu based image would be the easiest way forward.



Source: stackoverflow