在docker集装箱升级后,NPM会中断

我需要创build一个节点v6.10.3容器,但是最新的npm(目前是v5.4.1 )为本地包使用新的npmfunction。

这样的安装在我的Mac上没有任何问题,但是当我尝试用这样的安装创build一个docker镜像时,在更新npm之后,npm工具会崩溃,并抛出一堆关于丢失包的错误。

这里是Dockerfile的例子,我可以重现这个问题(请注意,我真正的Dockerfile更复杂):

 FROM ubuntu:xenial RUN apt-get update RUN apt-get install -y curl RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - RUN apt-get install -y nodejs RUN npm i -g npm RUN npm i -g lerna 

当生成进程到达线路RUN npm i -g lerna它引发了一堆错误,如:

 Error: Cannot find module 'process-nextick-args' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> (/usr/lib/node_modules/npm/node_modules/readable-stream/lib/_stream_readable.js:26:23) at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3) 

任何其他npm脚本将导致相同的错误。 重新安装npm所依赖的所有软件包似乎不是我的解决scheme。

我也尝试使用nvm在容器内部安装节点,但是我得到了同样的错误。

我的docker版本:

 Docker version 17.06.2-ce, build cec0b72 

这个Dockerfile有什么问题,我错过了什么?

我已经find了解决这个问题的方法,使用yarn

它看起来很奇怪,但它的作品:

 FROM ubuntu:xenial RUN apt-get update RUN apt-get install -y curl RUN curl -sL https://deb.nodesource.com/setup_6.x | bash - RUN apt-get install -y nodejs RUN npm i -g yarn RUN npm uninstall npm -g RUN yarn global add npm RUN npm i -g lerna 

不过,如果有人能够解释为什么原始解决scheme不起作用,或者帮助find解决问题的更好方法,那将是非常好的。