简体   繁体   English

如何在Linux Docker容器上安装NPM

[英]How can I install NPM on a Linux Docker container

I'm trying to set up a Linux-based Docker container to run an Angular web app as described in this question (warning: long!). 我正在尝试建立一个基于Linux的Docker容器来运行Angular Web应用程序,如本问题所述 (警告:很长!)。 I've got to the point where I've established that the problem I'm having there stems from the fact that the attempt to install NPM as part of the Docker container setup failed. 我已经确定了我遇到的问题是由于在Docker容器设置中尝试安装NPM失败的事实所致。

When I bash into the container, and run the command that's meant to do this: 当我bash到容器中并运行要执行此操作的命令时:

wget -O- https://deb.nodesource.com/setup_6.x

... I get an error: ...我得到一个错误:

ERROR: The certificate of 'deb.nodesource.com' is not trusted. 错误:“ deb.nodesource.com”证书不受信任。

ERROR: The certificate of 'deb.nodesource.com' hasn't got a known issuer. 错误:“ deb.nodesource.com”证书没有已知的发行者。

I'd love to be able to sort that issue the right way, but for now I'm just adding --no-check-certificate to the command, which bypasses that issue. 我很想能够以正确的方式进行排序这个问题,但现在我只是添加--no-check-certificate的命令,它绕过这个问题。

Now I have another error when I pipe that setup script into bash : 现在,当我将该安装脚本bashbash时,我又遇到了另一个错误:

Your distribution, identified as "stretch", is not currently supported, please contact NodeSource at https://github.com/nodesource/distributions/issues if you think this is incorrect or would like your distribution to be considered for support 当前不支持标识为“拉伸”的发行版,如果您认为这是不正确的或希望考虑将其视为支持发行版,请通过https://github.com/nodesource/distributions/issues与NodeSource联系。

Following the link in that message, I see a bunch of issues, only some of which are related. 通过该消息中的链接,我看到了很多问题,其中只有一些是相关的。 However, a bit of extra googling brought me to the FAQ , which in turn pointed me at issue #9 , which... has lots of people chipping in with different solutions, and references to other issues. 但是,额外的谷歌搜索使我进入了FAQ ,这反过来又使我指向了问题#9 ,该问题...有很多人忙于提供不同的解决方案,并涉及其他问题。 :-( :-(

The main suggestion seems to be to use sudo -E as follows: 主要建议似乎是使用sudo -E ,如下所示:

wget -qO- https://deb.nodesource.com/setup_6.x | sudo -E bash -

... but I don't have sudo . ...但是我没有sudo :-( :-(

UPDATE : I think first issue with wget and the second issue have the same root cause. 更新 :我认为与wget第一个问题和第二个问题具有相同的根本原因。 The Node setup script does a curl to some URL to test whether I'm on a supported version, and this is also failing due to HTTPS certificate issues. Node安装脚本会curl到某个URL以测试我是否在受支持的版本上,并且由于HTTPS证书问题,该操作也失败了。

If I do this: 如果我这样做:

curl -L https://deb.nodesource.com/setup

...then I get this error: ...然后我得到这个错误:

SSL certificate problem: self signed certificate in certificate chain SSL证书问题:证书链中的自签名证书

...which I can fix if I add the --insecure flag. ...如果添加--insecure标志,则可以修复。 But I think I need to fix the certificate issue before the Node setup script will work. 但是我认为我需要先解决证书问题,然后节点设置脚本才能起作用。

Any ideas how I can do that? 有什么想法可以做到吗? (Maybe that should be a different question?). (也许应该是一个不同的问题?)。

You should be able to fix the certificate issue by installing ca-certificates, before running the node setup script. 在运行节点设置脚本之前,您应该能够通过安装ca-certificate来解决证书问题。 You will probably need gnupg as well to validate the downloaded node version. 您可能还需要gnupg来验证下载的节点版本。

Example (with the assumption that you have a debian stretch based image): 示例(假设您具有基于debian Stretch的图像):

RUN apt-get update && \
    apt-get install -y ca-certificates gnupg curl wget --no-install-recommends && \
    rm -rf /var/lib/apt/lists/*
RUN <your node setup>

However you could just use the the command which is used in the official node image . 但是,您可以只使用官方节点映像中使用的命令。 Also I would prefer this over a setup script which is pulled from somewhere during the build of the image (and which may change between builds). 另外,与在映像构建期间从某处拉出的安装脚本(并且在构建之间可能会更改)相比,我更喜欢此设置脚本。 Directly executing downloaded scripts isn't security best practice as well. 直接执行下载的脚本也不是安全性最佳实践。

ENV NODE_VERSION 6.16.0

RUN buildDeps='xz-utils' \
    && ARCH= && dpkgArch="$(dpkg --print-architecture)" \
    && case "${dpkgArch##*-}" in \
      amd64) ARCH='x64';; \
      ppc64el) ARCH='ppc64le';; \
      s390x) ARCH='s390x';; \
      arm64) ARCH='arm64';; \
      armhf) ARCH='armv7l';; \
      i386) ARCH='x86';; \
      *) echo "unsupported architecture"; exit 1 ;; \
    esac \
    && set -ex \
    && apt-get update && apt-get install -y ca-certificates curl wget gnupg dirmngr $buildDeps --no-install-recommends \
    && rm -rf /var/lib/apt/lists/* \
    && for key in \
      94AE36675C464D64BAFA68DD7434390BDBE9B9C5 \
      FD3A5288F042B6850C66B31F09FE44734EB7990E \
      71DCFD284A79C3B38668286BC97EC7A07EDE3FC1 \
      DD8F2338BAE7501E3DD5AC78C273792F7D83545D \
      C4F0DFFF4E8C1A8236409D08E73BC641CC11F4C8 \
      B9AE9905FFD7803F25714661B63B535A4C206CA9 \
      77984A986EBC2AA786BC0F66B01FBB92821C587A \
      8FCCA13FEF1D0C2E91008E09770F7A9A5AE15600 \
      4ED778F539E3634C779C87C6D7062848A1AB005C \
      A48C2BEE680E841632CD4E44F07496B3EB3C1762 \
      B9E2F5981AA6E0CD28160D9FF13993A75599653C \
    ; do \
      gpg --batch --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys "$key" || \
      gpg --batch --keyserver hkp://ipv4.pool.sks-keyservers.net --recv-keys "$key" || \
      gpg --batch --keyserver hkp://pgp.mit.edu:80 --recv-keys "$key" ; \
    done \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-linux-$ARCH.tar.xz" \
    && curl -fsSLO --compressed "https://nodejs.org/dist/v$NODE_VERSION/SHASUMS256.txt.asc" \
    && gpg --batch --decrypt --output SHASUMS256.txt SHASUMS256.txt.asc \
    && grep " node-v$NODE_VERSION-linux-$ARCH.tar.xz\$" SHASUMS256.txt | sha256sum -c - \
    && tar -xJf "node-v$NODE_VERSION-linux-$ARCH.tar.xz" -C /usr/local --strip-components=1 --no-same-owner \
    && rm "node-v$NODE_VERSION-linux-$ARCH.tar.xz" SHASUMS256.txt.asc SHASUMS256.txt \
    && apt-get purge -y --auto-remove $buildDeps \
    && ln -s /usr/local/bin/node /usr/local/bin/nodejs

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM