Node not found in alpine docker

16,004

There is an official and up to date node package for alpine, you don't need to install it manually, just add this line in your Dockerfile:

RUN apk add nodejs=6.2.0-r0

Or you could use an existing nodejs alpine image:

FROM mhart/alpine-node:6.2.0

On a side note, the whole point of using an alpine based image is to get rid of the clutter, installing git, tar et al. is a waste of space IMHO.

Share:
16,004
Petru
Author by

Petru

Updated on June 04, 2022

Comments

  • Petru
    Petru almost 2 years

    I have the following 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
    

    Building the image gives me:

    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 
    

    How is it possible for node to not be found? It's installed in the correct directory, it's in the path, and has execution permission...

  • Petru
    Petru almost 8 years
    Well, I guess you are right. I wanted flexibility with building my custom node image, but I guess this works too.
  • Shanoor
    Shanoor almost 8 years
    @Petru you can also use mhart/alpine-node's Dockerfile, it gives you a functioning script and you can customize it like you want.
  • Petru
    Petru almost 8 years
    Yeah, I saw that. It seems overly complicated, that's why I tried to make my own simplified version. This was working with a debian base, but alpine gives this strange error :(
  • iamdeit
    iamdeit over 7 years
    I installed nodejs with RUN apk add nodejs=6.2.0-r0 but when I try to run a script with node index.js or nodejs index.js or /usr/bin/node index.js fails.
  • Shanoor
    Shanoor over 7 years
    @diugalde Alpine's repo doesn't have the 6.2.0 version anymore : pkgs.alpinelinux.org/packages?name=nodejs You'll have to use an existing version of nodejs or use the ready to use and actively maintained mhart/alpine-node Docker image.