node.jsdockercouchbasealpine-linuxmusl

Docker image for Nodejs and Couchbase SDK


So we have a nodejs micro-service using the NodeJS Couchbase SDK 3.2 We are trying to build a minimal docker image for our App using the Alpine base image but it seems the sdk needs more than what we have added to our base image.

Here is our dockerfile

FROM node:12-alpine3.13

RUN apk add --no-cache --virtual .gyp python3 make g++

WORKDIR /app

COPY package*.json ./

COPY .npmrc ./

RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install --only=production

RUN rm -rf .gyp

COPY . .

CMD [ “npm”, “start”]

We run into the following error,

Error: Error loading shared library libresolv.so.2: No such file or directory (needed by /app/node_modules/couchbase/build/Release/couchbase_impl.node)
at Object.Module._extensions…node (internal/modules/cjs/loader.js:1187:18)
at Module.load (internal/modules/cjs/loader.js:985:32)
at Function.Module._load (internal/modules/cjs/loader.js:878:14)
at Module.require (internal/modules/cjs/loader.js:1025:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.bindings [as default] (/app/node_modules/bindings/bindings.js:112:48)
at Object. (/app/node_modules/couchbase/dist/binding.js:70:35)
at Module._compile (internal/modules/cjs/loader.js:1137:30)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1157:10)
at Module.load (internal/modules/cjs/loader.js:985:32)

Is there any extra alpine lib we need to add ?

EDIT: This issue seems to be deeper than I thought. Refer to this thread : Use shared library that uses glibc on AlpineLinux

So it says Alpine uses musl as a c lib and apparently couchbase needs glibc ?

EDIT 2: This now works.

FROM node:12-alpine3.13
RUN apk add --no-cache --virtual .gyp python3 make g++
WORKDIR /app
COPY package*.json ./
COPY .npmrc ./
RUN npm cache clean --force
RUN rm -rf node_modules
RUN npm install
RUN npm install -g node-gyp
RUN npm install couchbase
RUN rm -rf .gyp
COPY . .
CMD [ “npm”, “start”]

Solution

  • Answered on the Couchbase forums: https://forums.couchbase.com/t/help-docker-image-for-nodejs-app-using-couchbase-sdk-3-2/33267

    In short, Alpine is not officially supported. You can read more information on platform compatibility in the documentation. There you can find a supported distro that works well for your needs.

    As was shared on the forums, the option --build-with-source will avoid using prebuilds, which may provide an adequate workaround for building on Alpine but its important to note that this is not the same as an officially supported platform.

    Feel free to follow up with any additional questions or concerns!