通过 Docker 问题快速安装
Posted
技术标签:
【中文标题】通过 Docker 问题快速安装【英文标题】:Express Sharp install via Docker issue 【发布时间】:2021-04-15 04:40:29 【问题描述】:我需要使用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 文件夹。 - 未找到纱线 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
【问题讨论】:
你如何运行你的容器?你使用任何卷映射吗? aha github.com/hagopj13/node-express-boilerplate/blob/master/… 你正在覆盖容器内的文件。 尝试将卷注释掉,然后运行 docker-compose,看看是否有帮助? 对不起伙计,我删除了这行但我得到了同样的错误。 您是否使用docker-compose up
来启动您的环境?
【参考方案1】:
Alpine 使用 musl 作为其 C 库。您可以使用不同的基于非 Alpine 的图像,例如 node:12-buster-slim
或任何其他非 Alpine 标记 here,或者尝试通过使用说明 here 设置 glibc 来使其工作。使用基于 Debian 或 Ubuntu 的映像将是最简单的方法。
【讨论】:
是的,完成了。但它没有连接mongodb服务器。 MongooseServerSelectionError: 连接 EHOSTUNREACH x:27017以上是关于通过 Docker 问题快速安装的主要内容,如果未能解决你的问题,请参考以下文章