mhart / alpine-node

Minimal Node.js Docker Images built on Alpine Linux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Node v12: Error when starting

dalisoft opened this issue · comments

Hello @mhart.

I got error

error loading shared library ld-linux-x86-64.so.2

when trying to run node.js app (i know it's because of binary), how i can fix this?

FROM mhart/alpine-node:12
RUN apk update && apk upgrade && \
    apk add --no-cache git
WORKDIR /app
COPY app/server.js ./
COPY package.json package-lock.json ./
RUN npm ci --prod

# Only copy over the node pieces we need from the above image
FROM mhart/alpine-node:slim-12
WORKDIR /app
COPY --from=0 /app .
# COPY . .
EXPOSE 3000
CMD ["node", "./app/server.js"]

Does this work for you?

docker run --rm mhart/alpine-node:slim-12 node --version

@mhart Yes, result is v12.4.0

I think it must be one of your dependencies. What node modules do you depend on?

@mhart
"nanoexpress": "^0.7.5" -> "uWebSockets.js": "uNetworking/uWebSockets.js#binaries".

On my machine with default Node.js v12 installed works good, only inside Docker this issue

@mhart A bit more log

Removing intermediate container fc8290ab9a14
 ---> b9ed890dbe7c
Successfully built b9ed890dbe7c
Successfully tagged backend_docker-multistage-demo-backend:latest
Recreating backend_docker-multistage-demo-backend_1 ... done
Attaching to backend_docker-multistage-demo-backend_1
docker-multistage-demo-backend_1  | /app/node_modules/uWebSockets.js/uws.js:29
docker-multistage-demo-backend_1  |             throw new Error('This version of µWS is not compatible with your Node.js build:\n\n' + e.toString());
docker-multistage-demo-backend_1  |             ^
docker-multistage-demo-backend_1  | 
docker-multistage-demo-backend_1  | Error: This version of µWS is not compatible with your Node.js build:
docker-multistage-demo-backend_1  | 
docker-multistage-demo-backend_1  | Error: Error loading shared library ld-linux-x86-64.so.2: No such file or directory (needed by /app/node_modules/uWebSockets.js/uws_linux_x64_72.node)
docker-multistage-demo-backend_1  |     at /app/node_modules/uWebSockets.js/uws.js:29:9
docker-multistage-demo-backend_1  |     at Object.<anonymous> (/app/node_modules/uWebSockets.js/uws.js:31:3)
docker-multistage-demo-backend_1  |     at Module._compile (internal/modules/cjs/loader.js:774:30)
docker-multistage-demo-backend_1  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
docker-multistage-demo-backend_1  |     at Module.load (internal/modules/cjs/loader.js:641:32)
docker-multistage-demo-backend_1  |     at Function.Module._load (internal/modules/cjs/loader.js:556:12)
docker-multistage-demo-backend_1  |     at Module.require (internal/modules/cjs/loader.js:681:19)
docker-multistage-demo-backend_1  |     at require (internal/modules/cjs/helpers.js:16:16)
docker-multistage-demo-backend_1  |     at Object.<anonymous> (/app/node_modules/nanoexpress/build/nanoexpress.js:5:27)
docker-multistage-demo-backend_1  |     at Module._compile (internal/modules/cjs/loader.js:774:30)
backend_docker-multistage-demo-backend_1 exited with code 1
dalisoft-MBP:backend dalisoft$ 

Yeah, so this is native binary built for glibc Linux – Alpine uses musl instead.

You can try adding apk add --no-cache libc6-compat to your Dockerfile – that will probably fix it. Or you can search for a musl build of uWebSockets

Thanks, i will try and post it here result, this can be marked as FAQ

There's a note on the README about musl vs glibc – but I'll add a note about libc6-compat

Thanks, then we can close this issue =)

I see notes already, now installing deps, thank you for fast reply and fix

No probs, hope it all works for you 👍

Ah, it didn't worked and recompiling module also not variant. I think i should use full Linux repo.

Looks like the owner of that project only has precompiled binaries, and doesn't allow recompiling?

https://github.com/uNetworking/uWebSockets.js

You could ask them if they could give you a way to compile the addons yourself

Author allows, on my machine i tried recompile, but never succeed before. Looks uWebSockets.js supports ARM binaries, i now trying ARM binary

Actually, I think they might be missing the latest binaries for Node v12 from v15.10.0:

https://github.com/uNetworking/uWebSockets.js/tree/v15.10.0

Try installing:

npm install uNetworking/uWebSockets.js#binaries

And then see if that works from there

Oh sorry – I just saw you already did that... nevermind!

Thanks for tip, this is my first trying with Docker microservices, so i am not expert, before used Docker only as DB (Redis, Postgres), now decided understand and learn better.
So, i am just getting expierence from these errors and bugs.