如何解决node-rdkafka在docker build中失败,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。
> @ start /> node app.js/node_modules/bindings/bindings.js:88 throw e ^Error: /node_modules/node-rdkafka/build/Release/node-librdkafka.node: invalid ELF header at Object.Module._extensions..node (module.js:664:18) at Module.load (module.js:554:32) at tryModuleLoad (module.js:497:12) at Function.Module._load (module.js:489:3) at Module.require (module.js:579:17) at require (internal/module.js:11:18) at bindings (/node_modules/bindings/bindings.js:81:44) at Object.<anonymous> (/node_modules/node-rdkafka/librdkafka.js:10:32) at Module._compile (module.js:635:30) at Object.Module._extensions..js (module.js:646:10)npm ERR! code ELIFECYCLEnpm ERR! errno 1npm ERR! @ start: `node app.js`npm ERR! Exit status 1npm ERR! npm ERR! Failed at the @ start 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-04-01T14_49_31_971Z-debug.log```
在nodejs中使用kafka包用docker部署时会出现以上错误。
解决方法,按如下Dockerfile进行build即可:
FROM node:8.11RUN mkdir -p /usr/src/appWORKDIR /usr/src/appCOPY . /usr/src/appRUN npm installRUN npm install node-rdkafka --no-package-lockCMD [ "npm", "start" ]
将node-rdkafka依赖从package.json中移出
然后单独执行:
RUN npm install node-rdkafka --no-package-lock
这样就可以了。
看完上述内容,你们掌握如何解决node-rdkafka在docker build中失败的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注编程网行业资讯频道,感谢各位的阅读!