【问题标题】:Updating npm in Docker image在 Docker 映像中更新 npm
【发布时间】:2018-06-12 02:33:17
【问题描述】:

我正在构建一个 Node.js Docker 映像:docker build . -t imagename,但是我不断收到有关 npm 版本的警告

npm WARN deprecated This version of npm lacks support for important features,
npm WARN deprecated such as scoped packages, offered by the primary npm
npm WARN deprecated registry. Consider upgrading to at least npm@2, if not the
npm WARN deprecated latest stable version. To upgrade to npm@2, run:
npm WARN deprecated 
npm WARN deprecated   npm -g install npm@latest-2
npm WARN deprecated 
npm WARN deprecated To upgrade to the latest stable version, run:
npm WARN deprecated 
npm WARN deprecated   npm -g install npm@latest
npm WARN deprecated 
npm WARN deprecated (Depending on how Node.js was installed on your system, you
npm WARN deprecated may need to prefix the preceding commands with `sudo`, or if
npm WARN deprecated on Windows, run them from an Administrator prompt.)
npm WARN deprecated 
npm WARN deprecated If you're running the version of npm bundled with
npm WARN deprecated Node.js 0.10 LTS, be aware that the next version of 0.10 LTS
npm WARN deprecated will be bundled with a version of npm@2, which has some small
npm WARN deprecated backwards-incompatible changes made to `npm run-script` and
npm WARN deprecated semver behavior.

但是我已经更新了 Node.js 版本,但它仍然无法工作:

node -v
v8.9.3
npm -v
5.6.0

我已经运行了npm -g install npm@latest,但仍然无法运行。

Dockerfile

FROM alpine:3.1

# Update
RUN apk add --update nodejs

# Install app dependencies
COPY package.json /src/package.json
RUN cd /src; npm -g install npm@latest

# Bundle app source
COPY . /src

CMD ["node", "--harmony","/src/app.js"]

可能是什么原因?我可以使用 node 运行应用程序就好了。

我正在运行 Ubuntu 16.04.3 LTS

【问题讨论】:

  • 你能把Dockerfile的内容贴出来
  • 使用 Dockerfile 更新问题
  • 你不使用官方节点镜像有什么原因吗? hub.docker.com/_/node
  • 另外值得检查的是您没有在 package.json 中指定旧的 Node 版本
  • 建议将 alpine 更新到最新版本 (3.7) 或使用 nodejs docker 镜像(来自 Dockerfile 中的 FROM)

标签: node.js docker npm


【解决方案1】:

在 Dockerfile 中,我使用了最新的 alpine 版本 FROM alpine:3.7,它可以工作。

【讨论】:

    【解决方案2】:

    在构建映像之前,您必须运行 docker image pull node 以在本地下载最新的节点(包括 npm)映像。

    希望有帮助!

    【讨论】:

    • 不,它没有。该问题具体说明了如何在 Docker 映像中更新 npm
    猜你喜欢
    • 2021-12-27
    • 2015-12-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 2020-10-14
    • 2016-10-03
    • 1970-01-01
    相关资源
    最近更新 更多