在高山 docker 中找不到节点

Node not found in alpine docker

我有以下 Dockerfile:

FROM alpine:3.3

RUN apk update \
  && apk add curl tar git gzip

RUN curl --retry 3 --retry-delay 20 --show-error --location --remote-name --silent "https://nodejs.org/dist/v6.2.0/node-v6.2.0-linux-x64.tar.gz" \
  && tar -xzf "node-v6.2.0-linux-x64.tar.gz" -C /usr/local --strip-components=1 --same-owner \
  && rm -rf "node-v6.2.0-linux-x64.tar.gz" \
  && ls -la /usr/local/bin && env \
  && /usr/local/bin/node -v \
  && npm cache clear

构建图像给我:

Sending build context to Docker daemon 13.51 MB
Step 1 : FROM alpine:3.3
 ---> 3e467a6273a3
Step 2 : RUN apk update     && apk add curl tar git gzip # bzip2 build-essential libfreetype6 libfreetype6-dev libfontconfig1 libfontconfig1-dev python python-dev python-pip python-virtualenv libkrb5-devENV NODE_VERSION=6.2.0
 ---> Using cache
 ---> 65f46657024a
Step 3 : RUN curl --retry 3 --retry-delay 20 --show-error --location --remote-name --silent "https://nodejs.org/dist/v6.2.0/node-v6.2.0-linux-x64.tar.gz"     && tar -xzf "node-v6.2.0-linux-x64.tar.gz" -C /usr/local --strip-components=1 --same-owner     && rm -rf "node-v6.2.0-linux-x64.tar.gz"     && ls -la /usr/local/bin && env     && /usr/local/bin/node -v     && npm cache clear
 ---> Running in 32967b91e2dd
total 26828
drwxrwxr-x    2 500      500           4096 May 17 19:40 .
drwxr-xr-x   10 root     root          4096 May 24 14:28 ..
-rwxrwxr-x    1 500      500       27459658 May 17 19:40 node
lrwxrwxrwx    1 500      500             38 May 17 19:40 npm ->     ../lib/node_modules/npm/bin/npm-cli.js
HOSTNAME=27c9668b3d5e
SHLVL=1
HOME=/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/
/bin/sh: /usr/local/bin/node: not found
The command '/bin/sh -c curl --retry 3 --retry-delay 20 --show-error --location --remote-name --silent "https://nodejs.org/dist/v6.2.0/node-v6.2.0-linux-x64.tar.gz"     && tar -xzf "node-v6.2.0-linux-x64.tar.gz" -C /usr/local --strip-components=1 --same-owner     && rm -rf "node-v6.2.0-linux-x64.tar.gz"     && ls -la /usr/local/bin && env     && /usr/local/bin/node -v     && npm cache clear' returned a non-zero code: 127
Build image failed 

怎么可能找不到节点呢? 它安装在正确的目录中,在路径中,并具有执行权限...

有一个official and up to date node package for alpine,你不需要手动安装它,只需在你的Dockerfile中添加这行:

RUN apk add nodejs=6.2.0-r0

或者您可以使用 existing nodejs alpine image:

FROM mhart/alpine-node:6.2.0

附带说明一下,使用基于 alpine 的图像的全部意义在于摆脱混乱,安装 git、tar 等。是对 space 恕我直言的浪费。