Solution to the failure of node rdkafka in docker build

Why can’t you stop buying 618?From the technical dimension to explore>>>

> @ 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 ELIFECYCLE
npm ERR! errno 1
npm ERR! @ start: `node app.js`
npm ERR! Exit status 1
npm 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```

When using Kafka package to deploy with docker in nodejs, the above errors will appear

The solution is to build the dockerfile as follows:

FROM node:8.11

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install
RUN npm install node-rdkafka --no-package-lock
CMD [ "npm", "start" ]

Remove the node rdkafka dependency from package. JSON

Then it is executed separately:

RUN npm install node-rdkafka --no-package-lock

That’s it

Similar Posts: