javascript - 通过 Docker 问题快速安装

标签 javascript node.js docker express sharp

我需要使用 sharp .它在我的工作区工作正常,但如果我通过 docker 部署,那么我会出错。我是执行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.
我认为Sharp在首次安装时是预先构建的。它使用了我的计算机的架构(darwin,arm)但是当它在 docker 上运行时,虽然它被再次构建,但该作品谈论的是我的计算机的架构。
我试过了
删除我工作区上的 node_modules 文件夹。 - 未找到 yarn pm2
npm install 在 docker 运行。 - 权限问题
我的 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

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

docker build . 当我这样做时,我看到我的服务器的锐利加载在 docker 日志中。
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
我的 Docker-撰写日志
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>
我认为,我需要在 docker 上安装Sharp以进行预建过程。
我不明白 docker 是如何工作的。这与我生活的业余爱好有关。
关系问题:
linux-x64 binaries cannot be used on the linuxmusl-x64 platform error

最佳答案

Alpine 将 musl 用于其 C 库。您可以使用不同的非 Alpine 图像,例如 node:12-buster-slim或任何其他非 Alpine 标签 here , 或尝试通过使用说明 here 设置 glibc 来使其工作.使用基于 Debian 或 Ubuntu 的镜像将是最简单的方法。

关于javascript - 通过 Docker 问题快速安装,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65646514/

相关文章:

javascript - 通过减少节点数来简化 SVG 路径字符串

Javascript,单击按钮后一秒钟显示对象

javascript - JQuery - 输入标签更改可见性属性

node.js - Dockerfile 在 docker 容器中运行 nodejs static-content

docker - docker 容器停止后 perf 无法解析符号

javascript - `this` 触发事件时属于窗口对象

node.js - 为什么 Mongoose 预 Hook 不适用于 fat-arrow 函数语法

javascript - NodeJS Fork 无法杀死子进程

docker - 我应该尽量减少 docker 层的数量吗?

python - docker swarm 抛出错误 "swarm already part of swarm"