Monday, 25 November 2019

docker image install nodejs

You can install nodejs by directly using node's docker image.

or if you already "extending" from another image, and you want to install nodejs on top of it. then you can directly learn from nodejs's official docker.


here is the official docker:

https://github.com/nodejs/docker-node

because the one i am building from has apk, so i will use apk, then i am following this:

https://github.com/nodejs/docker-node/blob/master/Dockerfile-alpine.template


the reason i am following this before the latest nodejs on apk is 9, and i cannot update to 10+.

so i have to use curl and unzip by following above link.



apk add --no-cache libstdc++

apk add --no-cache --virtual .build-deps curl


and then run below as


ARCH= && alpineArch="$(apk --print-arch)" \
       && case "${alpineArch##*-}" in \
         x86_64) \
           ARCH='x64' \
           CHECKSUM=CHECKSUM_x64 \
           ;; \
         *) ;; \
       esac \


if you cannot work above out, then you can try
apk --print-arch

if it return you "x86_64"

then
ARCH='x64'

then:


NODE_VERSION=10.17.0

above will setup and check your image's architecture and make sure later we can download the right version:


curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz"

then:


tar -xJf "node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz" -C /usr/local --strip-components=1 --no-same-owner

then:


ln -s /usr/local/bin/node /usr/local/bin/nodejs;

then you should have node now. you can check by run :  node -v




all in one:


```
ARCH='x64'

NODE_VERSION=10.17.0

apk add --no-cache libstdc++

apk add --no-cache --virtual .build-deps curl

curl -fsSLO --compressed "https://unofficial-builds.nodejs.org/download/release/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz"

tar -xJf "node-v$NODE_VERSION-linux-$ARCH-musl.tar.xz" -C /usr/local --strip-components=1 --no-same-owner

ln -s /usr/local/bin/node /usr/local/bin/nodejs;
```

if you don't have apk, then, you can try apt:

you may also need to check your architecture by different commands:

```
dpkg --print-architecture
or
apk --print-arch
```
for more info, you can check : https://github.com/nodejs/docker-node/tree/master/13

```
ARCH='x64'
NODE_VERSION=13.3.0

apt-get update
apt-get install curl

curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz"

tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner

```





No comments:

Post a comment