# Install jq and curl dependencies
apk add --no-cache jq curl
# Get major.minor version (that is v14.xx for node:14-alpine)
export NODE_MAJOR_MINOR_VERSION=$(node --version | cut -d. -f1,2)
# Dynamically receive the newest version for the major version of this image
export DOWNLOAD_VERSION=$(curl -fsSL --compressed https://unofficial-builds.nodejs.org/download/release/index.json | jq --raw-output ".[]|select(.version | startswith(\"$NODE_MAJOR_MINOR_VERSION\"))|.version" | head -1)
# Download the suitable tarball
curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/$DOWNLOAD_VERSION/node-$DOWNLOAD_VERSION-linux-x64-musl.tar.xz"
# Uncompress the tarball
tar -xJf "node-$DOWNLOAD_VERSION-linux-x64-musl.tar.xz" -C /usr/local --strip-components=1 --no-same-owner
# Overwrite symlink node -> nodejs
ln -sf /usr/local/bin/node /usr/local/bin/nodejs
在撰写本文
14.17.3
时已经发布。所以我想简单的答案是等待几天是你能做的最实际的事情。甚至有可能您必须重新拉取node:14-alpine
以获取更新的图像。但是如果你真的想看看需要做什么,你可以查看每个官方 docker 镜像的 Dockerfile。对于您的
node:14-alpine
图像,它位于此处:https ://github.com/nodejs/docker-node/blob/main/14/alpine3.14/Dockerfile从第 19 行开始,您会看到以下内容:
这就是他们为安装 node 的二进制发行版所做的(尽管从第 26 行开始,您可以看到自己编译所有内容)。不过,验证 sha256 校验和是可选的。
所以你可以做同样的事情并像这样覆盖高山容器内的节点版本。
编辑:如果您不喜欢对版本进行硬编码,可以使用 curl 和 jq (需要安装)自动化它: