Alex
Alex

Reputation: 38529

Installing nodejs on wordpress docker image - node: not found

I'm trying to install nodejs and npm onto a docker image, based from the official wordpress image, ultimately to install gulp.

My Dockerfile looks like this

FROM wordpress:4.9.8-php7.1-apache
RUN apt-get update
RUN apt-get install -y nodejs
RUN node -v
RUN npm install -g gulp
RUN npm install gulp

When I build the image, it appears to install nodejs, but then fail on something

Setting up nodejs (4.8.2~dfsg-1) ... update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode update-alternatives: warning: skip creation of /usr/share/man/man1/js.1.gz because associated file /usr/share/man/man1/nodejs.1.gz (of link group js) doesn't exist

and ultimately, I get the following error

/bin/sh: 1: node: not found

I can't work out why this would be?

The full output from the build log is below

Building wordpress
Step 1/6 : FROM wordpress:4.9.8-php7.1-apache
 ---> 18747ca95580
Step 2/6 : RUN apt-get update
 ---> Running in 8b7c3e8d34d6
Ign:1 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:2 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:3 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB]
Get:4 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Get:5 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2434 B]
Get:6 http://cdn-fastly.deb.debian.org/debian stretch-updates/main amd64 Packages [5148 B]
Get:7 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [7099 kB]
Get:8 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [385 kB]
Fetched 7794 kB in 3s (1984 kB/s)
Reading package lists...
Removing intermediate container 8b7c3e8d34d6
 ---> 1bcbd1ee66ef
Step 3/6 : RUN apt-get install -y nodejs
 ---> Running in 9b732a5af611
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libuv1
The following NEW packages will be installed:
  libuv1 nodejs
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 3524 kB of archives.
After this operation, 14.5 MB of additional disk space will be used.
Get:1 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 libuv1 amd64 1.9.1-3 [84.4 kB]
Get:2 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 nodejs amd64 4.8.2~dfsg-1 [3440 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 3524 kB in 1s (2812 kB/s)
Selecting previously unselected package libuv1:amd64.
(Reading database ... 13068 files and directories currently installed.)
Preparing to unpack .../libuv1_1.9.1-3_amd64.deb ...
Unpacking libuv1:amd64 (1.9.1-3) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_4.8.2~dfsg-1_amd64.deb ...
Unpacking nodejs (4.8.2~dfsg-1) ...
Setting up libuv1:amd64 (1.9.1-3) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Setting up nodejs (4.8.2~dfsg-1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/js.1.gz because associated file /usr/share/man/man1/nodejs.1.gz (of link group js) doesn't exist
Removing intermediate container 9b732a5af611
 ---> bbf198ce7820
Step 4/6 : RUN node -v
 ---> Running in 39269d307aa6
/bin/sh: 1: node: not found

UPDATE

My docker file now looks like this

FROM wordpress:4.9.8-php7.1-apache
RUN apt-get update 
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs

RUN nodejs -v
RUN npm -v

Running this with docker build . --no-cache results in the below output.

Summary: Node is v4.8.2, and npm is not found

Step 1/6 : FROM wordpress:4.9.8-php7.1-apache
 ---> 18747ca95580
Step 2/6 : RUN apt-get update
 ---> Running in 9bcb0285ff3f
Get:1 http://security.debian.org/debian-security stretch/updates InRelease [94.3 kB]
Ign:2 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Get:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease [91.0 kB]
Get:4 http://cdn-fastly.deb.debian.org/debian stretch Release [118 kB]
Get:5 http://cdn-fastly.deb.debian.org/debian stretch-updates/main amd64 Packages [5148 B]
Get:6 http://cdn-fastly.deb.debian.org/debian stretch Release.gpg [2434 B]
Get:7 http://security.debian.org/debian-security stretch/updates/main amd64 Packages [386 kB]
Get:8 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 Packages [7099 kB]
Fetched 7796 kB in 4s (1592 kB/s)
Reading package lists...
Removing intermediate container 9bcb0285ff3f
 ---> 7fb346c1196b
Step 3/6 : RUN apt-get install -y nodejs
 ---> Running in 6b42686c1c69
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
  libuv1
The following NEW packages will be installed:
  libuv1 nodejs
0 upgraded, 2 newly installed, 0 to remove and 1 not upgraded.
Need to get 3524 kB of archives.
After this operation, 14.5 MB of additional disk space will be used.
Get:1 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 libuv1 amd64 1.9.1-3 [84.4 kB]
Get:2 http://cdn-fastly.deb.debian.org/debian stretch/main amd64 nodejs amd64 4.8.2~dfsg-1 [3440 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 3524 kB in 1s (2250 kB/s)
Selecting previously unselected package libuv1:amd64.
(Reading database ... 13068 files and directories currently installed.)
Preparing to unpack .../libuv1_1.9.1-3_amd64.deb ...
Unpacking libuv1:amd64 (1.9.1-3) ...
Selecting previously unselected package nodejs.
Preparing to unpack .../nodejs_4.8.2~dfsg-1_amd64.deb ...
Unpacking nodejs (4.8.2~dfsg-1) ...
Setting up libuv1:amd64 (1.9.1-3) ...
Processing triggers for libc-bin (2.24-11+deb9u3) ...
Setting up nodejs (4.8.2~dfsg-1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
update-alternatives: warning: skip creation of /usr/share/man/man1/js.1.gz because associated file /usr/share/man/man1/nodejs.1.gz (of link group js) doesn't exist
Removing intermediate container 6b42686c1c69
 ---> cd6622204549
Step 4/6 : RUN nodejs -v
 ---> Running in 103bfc7b3396
v4.8.2
Removing intermediate container 103bfc7b3396
 ---> 978bd59b62df
Step 5/6 : RUN npm -v
 ---> Running in 9762ed0c24b4
/bin/sh: 1: npm: not found
The command '/bin/sh -c npm -v' returned a non-zero code: 127

Upvotes: 2

Views: 3627

Answers (1)

Sathyajith Bhat
Sathyajith Bhat

Reputation: 21851

For Ubuntu, the node.js executable is named nodejs, not node

$ cat Dockerfile
FROM wordpress:4.9.8-php7.1-apache
RUN apt-get update
RUN apt-get install -y nodejs
RUN nodejs -v

docker build .
Sending build context to Docker daemon  2.048kB
Step 1/6 : FROM wordpress:4.9.8-php7.1-apache
 ---> 18747ca95580
Step 2/6 : RUN apt-get update
 ---> Using cache
 ---> 416b334f6ea7
Step 3/6 : RUN apt-get install -y nodejs
 ---> Using cache
 ---> 0606aac728ee
Step 4/6 : RUN nodejs -v
 ---> Running in c300e7140695
v4.8.2

You get a very old version of Node, however. You can try this alternative approach which installs Node v8 (the current LTS) via Node's repository

FROM wordpress:4.9.8-php7.1-apache
RUN apt-get update && apt-get -y install gnupg2
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && apt-get install -y nodejs
RUN nodejs -v
RUN npm install -g gulp

Upvotes: 4

Related Questions