When running node.js in Docker, with sharp.js lib I am getting "invalid instruction" error and it exits with code 1.
This is likely related to "libvips" used by sharp.js, that requires C compiler. I tried using various base Docker images, and so far all get same error. Any suggestion would be helpful.
Here is minimum reproducible set:
When const sharp = require("sharp");
is commented out it works.
When it is included, getting this error Illegal instruction
Dockerfile
FROM node
RUN mkdir /app
WORKDIR /app
COPY . ./
RUN npm install
EXPOSE 4004
CMD ["node", "test.js"]
test.js
const app = require("express")();
const sharp = require("sharp");
app.get("/", (req, res) => {
res.send(`time: ${new Date()}`);
});
app.listen(4004, () => console.log(`listening on port 4004`));
package.json
{
"dependencies": {
"axios": "^0.24.0",
"express": "^4.17.1",
"fast-csv": "^4.1.1",
"pdfkit": "^0.13.0",
"sharp": "^0.29.3"
},
"devDependencies": {
"nodemon": "^2.0.15"
}
}
To build container image:
docker build -t test .
To start for interactive testing:
docker run -d --name test test tail -f /dev/null
docker exec -it test sh
then node test.js
When "sharp.js" is required, getting error Illegal instruction
otherwise not.
The comments suggest that this could happen when "alpine" base image is used, but in this case it happens with other node.js Docker images, too.
Hope this makes it a bit clearer.
The same sharp lib and code without outside of container without issues.