npm install -g apiconnect在Docker容器RHEL8中失败

问题描述

我需要基于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.

解决方法

我注意到您正在使用Node.js12.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"]
,

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...