tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.5k stars 1.93k forks source link

Unable to run @tensorflow/tfjs-node in Alpine linux #1425

Closed moustafa-a closed 4 years ago

moustafa-a commented 5 years ago

TensorFlow.js version

1.0.1

Describe the problem or feature request

Hi I'm trying to run tjfs-node in a Docker node:8-alpine image. I managed to install tfjs and tfjs-node but when I try to run my js code I get the following error:

Registration of backend tensorflow failed
Error: Error relocating /home/app/function/node_modules/@tensorflow/tfjs-node/build/Release/libtensorflow.so: __memcpy_chk: symbol not found
    at Object.Module._extensions..node (module.js:682:18)
    at Module.load (module.js:566:32)
    at tryModuleLoad (module.js:506:12)
    at Function.Module._load (module.js:498:3)
    at Module.require (module.js:597:17)
    at require (internal/module.js:11:18)
    at bindings (/home/app/function/node_modules/bindings/bindings.js:84:48)
    at /home/app/function/node_modules/@tensorflow/tfjs-node/dist/index.js:49:60
    at Environment.registerBackend (/home/app/function/node_modules/@tensorflow/tfjs-core/dist/environment.js:439:27)
    at Object.<anonymous> (/home/app/function/node_modules/@tensorflow/tfjs-node/dist/index.js:48:8)

Dockerfile

FROM node:8-alpine

RUN addgroup -S app && adduser app -S -G app
RUN apk --no-cache add curl \
    && echo "Pulling watchdog binary from Github." \
    && curl -sSL https://github.com/openfaas/faas/releases/download/0.9.14/fwatchdog > /usr/bin/fwatchdog \
    && chmod +x /usr/bin/fwatchdog \
    && apk del curl --no-cache

RUN apk --no-cache --virtual .build-deps add \
        python \
        make \
        g++ \
    && apk --no-cache --virtual .canvas-build-deps add \
        build-base \
        cairo-dev \
        jpeg-dev \
        pango-dev \
        giflib-dev \
        pixman-dev \
        pangomm-dev \
        libjpeg-turbo-dev \
        freetype-dev \
    && apk --no-cache --virtual .tensorflow-build-deps add \
        libc6-compat \
        alpine-sdk \
    && apk --no-cache add \
        pixman \
        cairo \
        pango \
        giflib \
        libjpeg \
        libc6-compat

WORKDIR /root/

# Turn down the verbosity to default level.
ENV NPM_CONFIG_LOGLEVEL warn

RUN mkdir -p /home/app

# Wrapper/boot-strapper
WORKDIR /home/app
COPY package.json ./

# This ordering means the npm installation is cached for the outer function handler.
RUN npm i --production

# Copy outer function handler
COPY index.js ./

# COPY function node packages and install, adding this as a separate
# entry allows caching of npm install runtime dependencies
WORKDIR /home/app/function
COPY function/*.json ./
RUN npm i --production || :

RUN apk del .build-deps --no-cache \
    && apk del .canvas-build-deps --no-cache \
    && apk del .tensorflow-build-deps --no-cache

# Copy in additional function files and folders
COPY --chown=app:app function/ .

WORKDIR /home/app/

# chmod for tmp is for a buildkit issue (@alexellis)
RUN chmod +rx -R ./function \
    && chown app:app -R /home/app \
    && chmod 777 /tmp

USER app

ENV cgi_headers="true"
ENV fprocess="node index.js"
EXPOSE 8080

HEALTHCHECK --interval=3s CMD [ -e /tmp/.lock ] || exit 1

CMD ["fwatchdog"]

package.json

{
  "name": "function",
  "version": "1.0.0",
  "description": "",
  "main": "handler.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@tensorflow/tfjs": "^1.0.1",
    "@tensorflow/tfjs-node": "^1.0.1",
    "canvas": "^2.4.0",
    "perf_hooks": "0.0.1"
  }
}
yos1p commented 4 years ago

Any progress on how to solve this issue?

yos1p commented 4 years ago

I think tfjs-node cannot run on Alpine linux. I have to change to Debian so that I can install necessary dependency. So if you use Docker, my suggestion is to use Debian-based image.

This works for me:

FROM node:buster-slim

COPY . .

RUN apt-get update && \ 
    apt-get install -y build-essential \
    wget \
    python3 \
    make \
    gcc \ 
    libc6-dev 

RUN npm install

EXPOSE 3000

CMD [ "node", "index.js" ]
malcolmcdixon commented 4 years ago

Is this likely to be resolved soon? Any other workarounds?

yuva-dev commented 4 years ago

I think tfjs-node cannot run on Alpine linux. I have to change to Debian so that I can install necessary dependency. So if you use Docker, my suggestion is to use Debian-based image.

This works for me:

FROM node:buster-slim

COPY . .

RUN apt-get update && \ 
    apt-get install -y build-essential \
    wget \
    python3 \
    make \
    gcc \ 
    libc6-dev 

RUN npm install

EXPOSE 3000

CMD [ "node", "index.js" ]

Man !!! you are a saviour ✌🏻

google-ml-butler[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

google-ml-butler[bot] commented 4 years ago

Closing as stale. Please @mention us if this needs more attention.

andredtr commented 3 years ago

Still having this errors was this solved?

mjpowersjr commented 3 years ago

I can confirm that I also have this issue.

kayorl commented 3 years ago

Me,too

wolasss commented 3 years ago

+1

awamser commented 3 years ago

+1

rthadur commented 3 years ago

cc @pyu10055 @lina128

awamser commented 3 years ago

This issue might be related to how Alpine uses musl libc. From the FAQ:

Binary compatibility is much more limited, but it will steadily increase with new versions of musl. At present, some glibc-linked shared libraries can be loaded with musl, but all but the simplest glibc-linked applications will fail if musl is dropped-in in place of /lib/ld-linux.so.2.

BorisWild commented 2 years ago

Still does not work on Alpine. Can't use docker image for node 'node:16-alpine'

pprathameshmore commented 1 year ago

Is there any way to make it work on Alpine?

pprathameshmore commented 1 year ago

This is what my configuration looks like for the docker image.

FROM node:16.20-buster-slim as builder
RUN apt-get update && \
    apt-get install -y python3-dev make gcc g++ git build-essential openssh-client openssl bash libc6-dev wget

Getting following issue

node_modules/lz4-asm/dist/lz4wasm.js:12
if(r)t=q?require("path").dirname(t)+"/":__dirname+"/",u=function(a,b){w||(w=require("fs"));x||(x=require("path"));a=x.normalize(a);return w.readFileSync(a,b?null:"utf8")},v=function(a){a=u(a,!0);a.buffer||(a=new Uint8Array(a));a.buffer||y("Assertion failed: undefined");return a},1<process.argv.length&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),process.on("uncaughtException",function(a){if(!(a instanceof z))throw a;}),process.on("unhandledRejection",y),n=function(a){process.exit(a)},
                                                                                                                                                                                                                                                                                                                                                                                                                                        ^

Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /srv/reviews/node_modules/@tensorflow/tfjs-node/lib/napi-v8/../../deps/lib/libtensorflow.so.2)
uzair004 commented 1 year ago

I think tfjs-node cannot run on Alpine linux. I have to change to Debian so that I can install necessary dependency. So if you use Docker, my suggestion is to use Debian-based image.

This works for me:

FROM node:buster-slim

COPY . .

RUN apt-get update && \ 
    apt-get install -y build-essential \
    wget \
    python3 \
    make \
    gcc \ 
    libc6-dev 

RUN npm install

EXPOSE 3000

CMD [ "node", "index.js" ]

Still facing issue with alpine, above solution seems to be working.