11

I am trying to build my own docker container based on alpine linux and I need to add multiple services in that container (yes it is not recommended as best practice but at the moment my org devops is bit behind the curve and demanding a single dockerfile for my custom image).

I was checking this article to find the way to install the latest version of nodejs with npm on alpine linux. However there seems to be no apk add nodejs@6 or something like that provided in this discussion.

Also it appears that alpine linux does not have the latest version of nodejs (v 8.X) in the repository here.

So do I pretty much have to install nodejs from source? But that option is very slower compared to just installing from alpine repo.

EDIT:

adding nodejs-current in dockerfile is giving another problem

Step ... : RUN apk update && apk add nodejs-current

---> Running in e430b4d279e5 fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/main/x86_64/APKINDEX.tar.gz fetch http://dl-cdn.alpinelinux.org/alpine/v3.4/community/x86_64/APKINDEX.tar.gz fetch http://nl.alpinelinux.org/alpine/edge/testing/x86_64/APKINDEX.tar.gz v3.4.6-213-gb6db4bd [http://dl-cdn.alpinelinux.org/alpine/v3.4/main] v3.4.6-160-g14ad2a3 [http://dl-cdn.alpinelinux.org/alpine/v3.4/community] v3.6.0-3765-g46dd4472f4 [http://nl.alpinelinux.org/alpine/edge/testing] OK: 8679 distinct packages available ERROR: unsatisfiable constraints: nodejs-current (missing): required by: world[nodejs-current]

fixer1234
  • 28,064

2 Answers2

23

We provide two nodejs packages:

  • nodejs in main – LTS version,
  • nodejs-current in community – the current version, as its called by upstream.

So if you want the latest version, install nodejs-current by running:

apk add nodejs-current

Currently it’s 7.10.1 in v3.6 (stable branch) or 8.5.0 in edge (unstable/rolling branch).

We don’t use @N suffixes like nodejs@6, it’s not a valid package name.

1

The simplest way for me was to use a specific version of Alpine.

In my use case I've used php:7.4-fpm-alpine image. And have to update it to php:7.4-fpm-alpine3.13 to be able to use Node 14.

php:7.4-fpm-alpine3.13 - Node 14
php:7.4-fpm-alpine3.12 - Node 12

Dockerfile example:

FROM php:7.4-fpm-alpine3.13

RUN apk update && apk add nodejs npm

Scofield
  • 111