10
我在數字海洋服務器的docker平臺上部署了一個簡單的node.js應用程序。無法在碼頭集裝箱中安裝npm?
//的package.json
{
"name": "docker-centos-hello",
"private": true,
"version": "0.0.1",
"description": "Node.js Hello world app on CentOS using docker",
"author": "Daniel Gasienica <[email protected]>",
"dependencies": {
"express": "3.2.4"
}
}
// app.js
var express = require('express');
var PORT = 3000;
var app = express();
app.get('/', function (req, res) {
res.send('Hello world\n');
});
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);
//搬運工文件
FROM dockerfile/nodejs
# Set the working directory
WORKDIR /src
EXPOSE 3000
CMD ["/bin/bash"]
的搬運工基本圖像是dockerfile /的NodeJS,這已經構建了一個node.js,我構建了這個映像:
docker build -t test1 /home/sizhe/docker/test
並運行映像:
docker run -it -p 8080:3000 -v /home/sizhe/docker/test1:/src test
通過運行圖像,我可以成功地放入容器中,應用程序文件都複製到容器中。當我試圖命令來安裝node.js的依賴性:
npm install
然而,NPM不能下載所有的包,用錯誤:
Linux 3.13.0-40-generic
npm ERR! argv "node" "/usr/local/bin/npm" "install"
npm ERR! node v0.10.35
npm ERR! npm v2.1.16
npm ERR! code ENOTFOUND
npm ERR! errno ENOTFOUND
npm ERR! syscall getaddrinfo
npm ERR! network getaddrinfo ENOTFOUND
npm ERR! network This is most likely not a problem with npm itself
npm ERR! network and is related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
謝謝!重新啓動泊塢窗('boot2docker restart')爲我工作。 – Leons
適用於Docker Machine @Leons建議爲我工作:'docker-machine restart' –
marcusstenbeck
謝謝,我會更新答案 –