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
  • 27,064
  • 61
  • 75
  • 116
Andy
  • 235
  • 1
  • 2
  • 8

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.

Stephen Rauch
  • 3,091
  • 10
  • 23
  • 26
Jakub Jirutka
  • 370
  • 2
  • 6
  • I’ve explicitly stated that you should install nodejs-current from Alpine branch v3.6 or edge, but you’re using v3.4 repositories… v3.4 is quite old. And mixing v3.4 with current testing is extremely bad idea btw… – Jakub Jirutka Sep 26 '17 at 18:48
  • Oh OK! In that case, I will have to wait until the standard PHP image I am using (php:7.1.9-fpm-alpine) update their alpine repo to V3.6 (they use V3.4). – Andy Sep 26 '17 at 19:01
  • No, in that case you should stop using such horribly outdated image! Just use base alpine image and install php7-fpm package. – Jakub Jirutka Sep 26 '17 at 19:02
  • 3
    BTW The answer is right, it’s not my fault that you haven’t read it properly, so it’s quite rude to downvote it. – Jakub Jirutka Sep 26 '17 at 19:05
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
  • 5