xue zhang
xue zhang

Reputation: 323

install node 15 on nginx alpine image

FROM nginx:1.19.9-alpine
RUN apk add --update nodejs npm

The version installed is 14.16.1 for the above Dockerfile, is it possible to install node 15.14.0?

Upvotes: 1

Views: 6832

Answers (1)

valiano
valiano

Reputation: 18551

For Node.js version 15.14.0, install the nodejs-current package from the edge community repository:

apk add nodejs-current=15.14.0-r0 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community

This will pin nodejs-current to version 15.14.0, so it will not be upgraded by apk upgrade. For allowing future upgrade, simply remove the =15.14.0-r0 part.

The latest npm package, 7.9.0, could be installed from edge as well, this time from the edge/main repository:

RUN apk add npm=7.9.0-r2 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main

This time, version pinning is required, otherwise apk will pick the stable npm version from Alpine 3.13, 14.16.1-r1.

Putting it together, the resulting Dockerfile:

FROM nginx:1.19.9-alpine
RUN apk add nodejs-current --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community && \
    apk add npm=7.9.0-r2 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/main
RUN node --version && npm --version

Version check for node and npm:

/ # node --version
v15.14.0
/ # npm --version
7.9.0

Upvotes: 1

Related Questions