【问题标题】:npm install -g apiconnect fails in Docker container (RHEL8)npm install -g apiconnect 在 Docker 容器 (RHEL8) 中失败
【发布时间】:2021-01-07 03:15:26
【问题描述】:

我需要构建一个基于 RHEL 8 的容器,然后安装 LoopBack 和 IBM ApiConnect。

  • 使用 RedHat Enterprise Linux 8 运行容器
docker run -it --name api-framework-rhel8 -v ~/api-framework-rhel8:/api-framework-rhel8 registry.access.redhat.com/ubi8/ubi:8.1 bash
  • 将 Node.js (v12) 安装到容器中
curl -sL https://rpm.nodesource.com/setup_12.x | bash -

yum install -y nodejs
  • 安装开发工具以构建原生插件
yum install gcc-c++ make

yum install python38

yum install python27
  • 使用alternativespython 映射到python2(或python3) - 在api-connect 安装过程中都尝试了,但都失败了。
alternatives --set python /usr/bin/python2
  • 安装 LoopBack
npm install -g loopback-cli

安装 ApiConnect

npm install -g --unsafe-perm=true --allow-root apiconnect

但是,这会失败并显示错误消息(来自控制台,2 套):

gyp: [Errno 2] No such file or directory while executing command '['python', './generate_build_id.py']' in binding.gyp while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
gyp ERR! System Linux 4.19.76-linuxkit
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /usr/lib/node_modules/apiconnect/node_modules/appmetrics
gyp ERR! node -v v12.18.4
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok 

注意python2python3安装在/usr/bin下,可以从容器中访问,但是python不能被调用。

来自控制台的第二组错误:

Error: appmetrics@3.1.3 install: `node extract_all_binaries.js || node-gyp rebuild`
error code ELIFECYCLE
error errno 1
error appmetrics@3.1.3 install: `node extract_all_binaries.js || node-gyp rebuild`
error Exit status 1
error Failed at the appmetrics@3.1.3 install script.
error This is probably not a problem with npm. There is likely additional logging output above.

【问题讨论】:

  • 尝试使用--loglevel verbose 运行 npm install 以获得更多详细信息,但作为初步猜测,也许您没有安装 Python 2.7?这可能是必需的。
  • 嗨,马特,执行了 yum install -y python27,然后尝试使用 --loglevel verbose 运行。 ``` 60183 详细堆栈错误:appmetrics@3.1.3 安装:node extract_all_binaries.js || node-gyp rebuild60190 错误代码 ELIFECYCLE 60191 错误 errno 1 60192 错误 appmetrics@3.1.3 安装:node extract_all_binaries.js || node-gyp rebuild60192 错误退出状态 1 60193 错误在 appmetrics@ 失败3.1.3 安装脚本。 60193 错误 这可能不是 npm 的问题。上面可能有额外的日志输出。 ```
  • 将需要查看更多的日志输出。除了错误消息之外,尝试在错误行之前捕获更多日志并将它们添加到上面的问题中。 (评论不适用于这种类型的输出!)
  • 马特,我已经更新了上述问题中的错误。我还可以在 GitHub 中提供完整的控制台消息和日志文件。
  • 在python安装脚本后运行python --version检查python默认使用哪个版本构建。

标签: docker loopback apiconnect rhel8


【解决方案1】:

这个 Node 版本对我有用: 节点-v8.8.1

【讨论】:

    【解决方案2】:

    我注意到您使用的是 Node.js 12.x。 apiconnect 工具包仅支持 Node.js 10.x。

    我尝试了您问题中的大部分步骤,但切换到节点 10,这似乎解决了问题。

    另外,请务必安装 python27 并运行 alternatives --set python /usr/bin/python2,如您所述。

    这是我使用的完整 Dockerfile:

    FROM registry.access.redhat.com/ubi8/ubi:8.1
    
    RUN yum update -y && \
        yum install -y python27 gcc-c++ make
    
    RUN alternatives --set python /usr/bin/python2
    
    RUN curl -sL https://rpm.nodesource.com/setup_10.x | bash - && \
        yum install -y nodejs
    
    RUN npm i -g --unsafe-perm=true apiconnect
    
    CMD ["bash"]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-15
      • 2017-09-27
      • 1970-01-01
      • 2022-11-04
      • 2020-05-25
      • 2018-07-04
      • 1970-01-01
      • 2021-05-08
      相关资源
      最近更新 更多