在Alpine Linux上安装Node.js版本12时出错

时间:2020-09-15 20:58:10

标签: node.js linux docker dockerfile alpine

我正在使用以下Dockerfile如下安装alpine linux 并引用了以下堆栈溢出答案:-How to install Nodejs v13.0.1 in alpine:3.8?

FROM alpine:3.9

ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
RUN echo "${ALPINE_MIRROR}/v3.10/community/" >> /etc/apk/repositories
RUN apk update && apk add glibc nodejs-current --repository="http://dl-cdn.alpinelinux.org/alpine/v3.10/community/"
RUN node --version

节点版本导致错误

Error relocating /usr/bin/node: uv_gettimeofday: symbol not found
Error relocating /usr/bin/node: uv_udp_connect: symbol not found
Error relocating /usr/bin/node: uv_thread_create_ex: symbol not found
Error relocating /usr/bin/node: uv_udp_getpeername: symbol not found
The command '/bin/sh -c node --version' returned a non-zero code: 127

如何解决此问题并安装节点12.4.0-r0?

2 个答案:

答案 0 :(得分:1)

您不应安装nodejs-current,因为此软件包有助于从nodejs版本的边缘存储库安装* nodejs当前版本 不存在。

在您的情况下, nodejs 12.x package 已经存在,因此如果要安装旧版本而不是nodejs,则应安装nodejs-current

FROM alpine:3.9
ENV ALPINE_MIRROR "http://dl-cdn.alpinelinux.org/alpine"
RUN echo "${ALPINE_MIRROR}/v3.11/main/" >> /etc/apk/repositories
RUN apk add nodejs --repository="http://dl-cdn.alpinelinux.org/alpine/v3.11/main/"
RUN node --version

输出

Removing intermediate container a201832610e0
 ---> b0919df78aef
Step 5/5 : RUN node --version
 ---> Running in cd7950f9303b
v12.15.0
Removing intermediate container cd7950f9303b
 ---> ce54af976f81
Successfully built ce54af976f81

答案 1 :(得分:0)

alpine:3.12 现在使用 node v12.22.1

来自高山:3.12

运行节点 --version