【问题标题】:Error installing Sharp in docker container在 docker 容器中安装 Sharp 时出错
【发布时间】:2021-08-06 03:39:12
【问题描述】:

当在本地运行 npm install 时,一切都很好,但是一旦我在我的 docker 容器中尝试它,我就会收到以下错误:

/api/node_modules/sharp/lib/constructor.js:1
    Something went wrong installing the "sharp" module
    
    Error relocating /api/node_modules/sharp/build/Release/../../vendor/8.10.6/lib/libvips-cpp.so.42: _ZNSt7__cxx1119basic_ostringstreamIcSt11char_traitsIcESaIcEEC1Ev: symbol not found

任何帮助非常感谢

Docker 镜像非常简单:

FROM node:12.13.0-alpine AS alpine

WORKDIR /api

COPY package.json .

RUN npm install

【问题讨论】:

  • 您是否有包含主机的node_modules 树的.dockerignore file?主机和容器环境可能非常不同(特别是如果容器是基于 Alpine 的),您需要确保从头开始安装包。
  • @DavidMaze 我没有 - 我最终通过消除过程使这个工作正常进行,我必须在我的 Dockerfile 中添加一个明确的RUN npm config set unsafe-perm true,这很好。

标签: docker npm docker-compose npm-install sharp


【解决方案1】:

在我的情况下,在为 Sharp 搜索 github 问题尝试了许多不同的选项后,将此行添加到我的 Dockerfile 修复了它:

RUN npm config set unsafe-perm true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2018-03-02
    相关资源
    最近更新 更多