oransel/node-talib

Error in Docker Alpine TA_AVGDEV_Lookback: symbol not found

micheledisalvatore opened this issue · 6 comments

Hi guys. I'm trying to run a simple node app with this library running in docker, but at the startup of the container, an error occurs in TALIB and the app stops running.

This is the error

Error: Error relocating /app/node_modules/talib/build/Release/talib.node: TA_AVGDEV_Lookback: symbol not found
    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1188:18

And the Dockerfile I'm using

FROM node:14-alpine

RUN mkdir /app
WORKDIR /app
COPY . /app

RUN apk add --update python make g++

RUN yarn install --production --ignore-optional

CMD node .

Am I missing any dependency in my docker file?

Thank you for your help.

I've replaced node:14-alpine with node:14 and it works, but the image size jumped from 485MB (alpine) to 1.09GB (generic node), it would be great to know what libraries are required to run TALIB

I am not familiar with Alpine. May be you are missing node-gyp.

@oransel thank you for your help, I've tried adding it RUN apk add --no-cache --virtual .gyp python make g++ gcc but keeping the same error... if you have any other idea, please let me know, I'll check it out.

@micheledisalvatore I found a workaround. Multi staging Dockerfile. We can make a build via node-slim and then copy files to alpine. Here is the base version of the Dockerfile.
The total size of the image with my app is 260MB (alpine)

#
# ================ base-install-env ================
#
FROM node:14.5-slim as base-install-env

WORKDIR /code

RUN set -x && \
  apt-get update && \
  apt-get install -y \
          apt-transport-https \
          build-essential \
          make \
          python

#
# ================ app-env ================
#
FROM base-install-env as app-env

COPY ./package.json ./yarn.lock /code/

RUN set -x && \
    yarn global add ts-node node-prune modclean --loglevel=warn && \
    yarn install --production --loglevel=warn && \
    node-prune && \
    modclean -r -n default:safe

#
# ================ builder-env ================
#
FROM app-env as builder-env

RUN set -x && \
    yarn install --loglevel=warn

#
# ================ build ================
#
FROM builder-env as build

COPY ./tsconfig.json /code/
COPY ./src /code/src

RUN npm run build:prod

#
# ================ app ================
#
FROM node:14.5-alpine as app
WORKDIR /code

COPY ./package.json /code/
COPY --from=build /code/dist /code/dist
COPY --from=app-env /code/node_modules /code/node_modules

EXPOSE 3000
CMD ["npm", "run", "start:prod", "main"]

After manual deleting trash, I've achieved 179MB 🧨

    rm -rf node_modules/rxjs/src/ && \
    rm -rf node_modules/rxjs/bundles/ && \
    rm -rf node_modules/rxjs/_esm5/ && \
    rm -rf node_modules/rxjs/_esm2015/ && \
    rm -rf node_modules/typescript/ && \
    rm -rf node_modules/@types/ && \
    rm -rf node_modules/talib/src/ && \
    rm -rf node_modules/typeorm/browser/ && \
    rm -rf node_modules/ccxt/dist/ && \
    find node_modules -type f -name "*.ts" -delete && \
    find node_modules -type f -name "*.spec.*" -delete && \
    find node_modules -type f -name "*.test.*" -delete && \
    find node_modules -type d -name "__tests__" -delete

@korniychuk wow a great achievement! Thank you for sharing