如何解决node-rdkafka在docker build中失败

2023-04-14 00:44:00 如何解决 Node

如何解决node-rdkafka在docker build中失败

当我尝试在docker中使用node-rdkafka时,我遇到了一个问题。我正在尝试使用node-rdkafka来连接到我的Kafka集群,但是当我尝试build镜像时它会失败。

我的Dockerfile如下所示:

FROM node:8.9.4-alpine as builder

RUN apk add --no-cache python make g++

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build

FROM node:8.9.4-alpine

WORKDIR /usr/src/app

COPY --from=builder /usr/src/app/package*.json ./

RUN npm install --production

COPY --from=builder /usr/src/app/dist ./dist

CMD [ "npm", "start" ]

当我尝试build这个Dockerfile时,我得到以下错误:

npm ERR! Linux 4.9.93-linuxkit-aufs

npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"

npm ERR! node v8.9.4

npm ERR! npm v5.6.0

npm ERR! code ELIFECYCLE

npm ERR! node-rdkafka@2.2.2 install: `node-gyp rebuild`

npm ERR! Exit status 1

npm ERR!

npm ERR! Failed at the node-rdkafka@2.2.2 install script.

npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

npm ERR! /root/.npm/_logs/2018-03-22T16_57_45_764Z-debug.log

error Command failed with exit code 1.

info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

The command '/bin/sh -c yarn run build' returned a non-zero code: 1

我不确定是什么导致了这个错误,我已经尝试了很多不同的方法来解决它,但是都没有成功。我希望有人能帮助我解决这个问题。

相关文章