代码之家  ›  专栏  ›  技术社区  ›  Alex

在wordpress docker映像上安装nodejs-节点:未找到

  •  2
  • Alex  · 技术社区  · 6 年前

    我试图安装nodejs和npm到一个docker镜像上,基于官方wordpress镜像,最终安装gulp。

    我的档案看起来是这样的

    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)。。。更新备选方案:使用 /usr/bin/nodejs以自动模式提供/usr/bin/js(js) 更新备选方案:警告:跳过创建 /usr/share/man/man1/js.1.gz,因为关联的文件 /Ur/PoS/MAN/MAN1/NODEJ.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 回复  |  直到 6 年前
        1
  •  4
  •   Sathyajith Bhat ron tornambe    6 年前

    对于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 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