use*_*624 12 node.js npm docker
我正在数字海洋服务器的docker平台上部署一个简单的node.js应用程序.
// 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 <daniel@gasienica.ch>",
"dependencies": {
"express": "3.2.4"
}
}
Run Code Online (Sandbox Code Playgroud)
// 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);
Run Code Online (Sandbox Code Playgroud)
// docker文件
FROM dockerfile/nodejs
# Set the working directory
WORKDIR /src
EXPOSE 3000
CMD ["/bin/bash"]
Run Code Online (Sandbox Code Playgroud)
docker基础映像是dockerfile/nodejs,它构建了一个node.js,我构建了映像:
docker build -t test1 /home/sizhe/docker/test
Run Code Online (Sandbox Code Playgroud)
并运行图像:
docker run -it -p 8080:3000 -v /home/sizhe/docker/test1:/src test
Run Code Online (Sandbox Code Playgroud)
通过运行映像,我可以成功进入容器,将app文件全部复制到容器中.当我尝试使用命令安装node.js依赖项时:
npm install
Run Code Online (Sandbox Code Playgroud)
但是,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'
Run Code Online (Sandbox Code Playgroud)
Jir*_*ser 17
确保dns设置正确.docker服务重启后,我遇到了一些问题.如果它没有帮助您可能想要使用--dns 8.8.8.8docker开关.
重启docker服务:
sudo systemctl restart dockerboot2docker restartdocker-machine restart <machine_name>此外,我做了类似的事情(nodejs图像),但我已经使用了另一个基本图像,随时可以使用我的回购中所需的任何内容.
| 归档时间: |
|
| 查看次数: |
5433 次 |
| 最近记录: |