Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
moustafa-a opened this issue Mar 19, 2019 · 17 comments
Closed

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

moustafa-a opened this issue Mar 19, 2019 · 17 comments

Comments

@moustafa-a
Copy link

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
Copy link

yos1p commented Mar 8, 2020

Any progress on how to solve this issue?

@yos1p
Copy link

yos1p commented Mar 8, 2020

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
Copy link

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

@yuva-dev
Copy link

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
Copy link

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
Copy link

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

@andredtr
Copy link

andredtr commented Dec 4, 2020

Still having this errors was this solved?

@mjpowersjr
Copy link

I can confirm that I also have this issue.

@kayorl
Copy link

kayorl commented Feb 5, 2021

Me,too

@wolasss
Copy link

wolasss commented Feb 5, 2021

+1

1 similar comment
@awamser
Copy link

awamser commented Mar 19, 2021

+1

@rthadur
Copy link
Contributor

rthadur commented Mar 19, 2021

cc @pyu10055 @lina128

@awamser
Copy link

awamser commented Mar 19, 2021

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
Copy link

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

@pprathameshmore
Copy link

Is there any way to make it work on Alpine?

@pprathameshmore
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests