为什么这个docker构建失败了?

时间:2018-04-10 01:59:40

标签: docker

下面是我的Dockerfile my-docker-file

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y python python-pip git-all python-dev libxml2-dev libxslt1-dev libmysqlclient-dev gunicorn python-pycurl libcurl4-openssl-dev
RUN apt-get install -y rubygems-integration inotify-tools
RUN gem install sass -v 3.3.14
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN npm install jsmin -g

但它在最后一步失败了(见下文)。为什么会发生这种情况?我该如何解决?

$ docker build -f /path/to/my/project/my-docker-file .

<... FIRST EIGHT STEPS SNIPPED ...>

 ---> 742601020ac5
Step 9/9 : RUN npm install jsmin -g
 ---> Running in 6528f8aa90cc
npm http GET https://registry.npmjs.org/jsmin
npm http GET https://registry.npmjs.org/jsmin
npm http GET https://registry.npmjs.org/jsmin
npm ERR! Error: CERT_UNTRUSTED
npm ERR!     at SecurePair.<anonymous> (tls.js:1370:32)
npm ERR!     at SecurePair.EventEmitter.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:982:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:469:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:320:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:366:25)
npm ERR!     at doWrite (_stream_writable.js:223:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:213:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:180:11)
npm ERR!     at write (_stream_readable.js:583:24)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 4.9.87-linuxkit-aufs
npm ERR! command "/usr/bin/nodejs" "/usr/bin/npm" "install" "jsmin" "-g"
npm ERR! cwd /
npm ERR! node -v v0.10.25
npm ERR! npm -v 1.3.10
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /npm-debug.log
npm ERR! not ok code 0
The command '/bin/sh -c npm install jsmin -g' returned a non-zero code: 1

2 个答案:

答案 0 :(得分:2)

不是最好的解决方案,但在这种情况下,这对我有用

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y python python-pip git-all python-dev libxml2-dev libxslt1-dev libmysqlclient-dev gunicorn python-pycurl libcurl4-openssl-dev
RUN apt-get install -y rubygems-integration inotify-tools
RUN gem install sass -v 3.3.14
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN npm config set strict-ssl false <-- Ignore the SSL cert
RUN npm install jsmin -g

更新

更好的解决方案是使用npm注册表的http版本,如下所示

FROM ubuntu:14.04
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y python python-pip git-all python-dev libxml2-dev libxslt1-dev libmysqlclient-dev gunicorn python-pycurl libcurl4-openssl-dev
RUN apt-get install -y rubygems-integration inotify-tools
RUN gem install sass -v 3.3.14
RUN apt-get install -y nodejs
RUN apt-get install -y npm
RUN npm config set registry http://registry.npmjs.org/
RUN npm install jsmin -g

答案 1 :(得分:0)

错误,因为尝试安装nodejs Error: CERT_UNTRUSTED

时不受信任的存储库

可能您可以尝试将nodejs的安装更改为此类

RUN curl -sL https://deb.nodesource.com/setup_9.x | bash -
RUN apt-get install -y nodejs