Sharp: Error loading shared library /app/node_modules/sharp/build/Release/sharp.node: Exec format error

Created on 13 Oct 2017  路  4Comments  路  Source: lovell/sharp

I'm attempting to use Sharp in a Docker container with alpine Linux. But I'm getting this error:

Error loading shared library /app/node_modules/sharp/build/Release/sharp.node: Exec format error

This is what my Dockerfile looks like:

FROM mhart/alpine-node:8

RUN npm install -p

RUN apk --no-cache add -t .build-deps \
        gcc \
        libc-dev\
        make \
        libpng-dev \
        g++ \
        git && \
    mkdir -p /opt/google && \
    cd /opt/google && \
    git clone https://github.com/google/guetzli.git && \
    cd guetzli && \
    make && \
    cd /opt  && \
    mv /opt/google/guetzli/bin/Release/guetzli . && \
    rm -fr /opt/google && \
    apk --no-cache add libpng libstdc++ && \
    apk -- del .build-deps

WORKDIR /app
COPY . .

EXPOSE 3000
CMD ["npm", "start"]

This is the command I'm running after building the image.

docker run -it -p 3000:3000 -v $PWD:/app image:latest
question

Most helpful comment

Hello, to use Alpine you'll need to install libvips

You'll also need to prevent node_modules being copied into the container if you're not using Alpine on the "outside" and probably also need to move the RUN npm install to occur after the COPY.

All 4 comments

Hello, to use Alpine you'll need to install libvips

You'll also need to prevent node_modules being copied into the container if you're not using Alpine on the "outside" and probably also need to move the RUN npm install to occur after the COPY.

Thanks for your help @lovell. I'm still having some issues. I'm getting the following error:

gyp: Call to 'if readelf -Ws "$(PKG_CONFIG_PATH=":$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig" pkg-config --variable libdir vips-cpp)/libvips-cpp.so" | c++filt | grep -qF __
cxx11;then echo "1";else echo "0";fi' returned exit status 0 while in binding.gyp. while trying to load binding.gyp

My Dockerfile now looks like:

FROM node:8.7.0-alpine

RUN apk add vips-dev fftw-dev --update-cache --repository https://dl-3.alpinelinux.org/alpine/edge/testing/

RUN apk --no-cache add -t .build-deps \
        gcc \
        libc-dev\
        make \
        libpng-dev \
        g++ \
        git && \
    mkdir -p /opt/google && \
    cd /opt/google && \
    git clone https://github.com/google/guetzli.git && \
    cd guetzli && \
    make && \
    cd /opt  && \
    mv /opt/google/guetzli/bin/Release/guetzli . && \
    rm -fr /opt/google && \
    apk --no-cache add libpng libstdc++ && \
    apk -- del .build-deps

RUN mkdir -p /home/nodejs/app
WORKDIR /home/nodejs/app

COPY . .
RUN npm install --production

EXPOSE 3000
CMD ["npm", "start"]

It looks like you're erroneously removing the build dependencies (make, g++ etc.) before npm install is run.

Yes that was it! Thank you!

Was this page helpful?
0 / 5 - 0 ratings