在Wordpress Docker映像上安装Node.js-节点:找不到

时间:2018-08-06 16:16:43

标签: node.js docker

我试图根据官方的wordpress映像将nodejs和npm安装到docker映像上,最终安装gulp。

我的Dockerfile看起来像这样

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

构建映像时,它似乎安装了Node.js,但是在某些方面失败了

  

设置nodejs(4.8.2〜dfsg-1)... update-alternatives:使用   / usr / bin / nodejs以自动模式提供/ usr / bin / js(js)   update-alternatives:警告:跳过创建   /usr/share/man/man1/js.1.gz,因为关联的文件   /usr/share/man/man1/nodejs.1.gz(链接组js)不存在

最终,我得到以下错误

  

/ bin / sh:1:节点:找不到

我不知道为什么会这样?

下面是构建日志的完整输出

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

更新

我的docker文件现在看起来像这样

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

使用docker build . --no-cache运行此命令将得到以下输出。

摘要:节点为v4.8.2,未找到npm

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

1 个答案:

答案 0 :(得分:3)

对于Ubuntu,node.js可执行文件名为nodejs,而不是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

但是,您会获得非常旧的Node版本。您可以尝试通过Node的存储库

安装Node v8 (the current LTS)的另一种方法
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