当前位置: 首页 > 知识库问答 >
问题:

在wordpress docker映像上安装nodejs-Node:找不到

拓拔骁
2023-03-14

我试图将nodejs和npm安装到基于官方wordpress映像的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

当我构建映像时,它似乎安装了nodejs,但却失败了

正在设置nodejs(4.8.2~DFSG-1)...update-备选项:在自动模式下使用/usr/bin/nodejs提供/usr/bin/js(js)update-备选项:警告:跳过/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个答案

施知
2023-03-14

对于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的存储库安装NodeV8(当前的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
 类似资料:
  • 我是Docker的新手。我创建了以下Dockerfile并运行它: 来自Centos:最新的ENV container docker运行YUM-Y更新&&yum clean all 我收到以下错误/输出: root@ggnlabvm-juper6:~/docker_test#docker build-t test。 将构建上下文发送到Docker守护进程2.048 kB 步骤1/3:来自Cento

  • 我试图在我的Windows开发机器上安装node-ffi,但是安装失败。根据node-ffi网页,应该支持Windows。然而,看起来gyp试图通过sh执行一些东西,这(显然)在我的系统中不存在。有什么想法吗? 我的系统是Windows7x64。

  • 我有一个Docker映像,它是一个Node.js应用程序。应用程序从本地运行的Redis检索一些配置值。因此,我试图在Docker映像的同一容器中安装和运行Redis。 我如何扩展Docker文件并在其中配置Redis? 截至目前,Dockerfile如下所示:

  • 这是我第一次尝试创建Docker形象,我希望有人能帮助我。我的Dockerfile大致如下所示: 基本上,我只是为了扩展jar文件而安装Java。运行makefile时,出现以下错误: /bin/sh:1:/usr/lib/jvm/java-7-openjdk-amd64:权限被拒绝 我一直试图效仿这个例子:https://registry.hub.docker.com/u/barnybug/op

  • 问题内容: 我很难在Linux上安装Qt。我在网站上下载了.run文件并安装了Qt。但是,当我尝试使用Qtcreator编译默认的Hello World项目时,得到以下信息: 我能够通过发出以下命令解决问题: 但是,我对解决方案不满意,因为我想使用Qt5,而我下载的库的名称暗示了版本4。有人可以解释发生了什么,并告诉我解决方案是否正确吗?如果没有,我应该怎么做才能在Linux上运行Qt。 附加问题

  • 我得到了 我觉得我错过了一些极其简单的东西,但我却无法完全弄明白。如有任何帮助,将不胜感激。