加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

node.js – 不能在docker容器中安装npm?

发布时间:2020-12-16 03:31:30 所属栏目:安全 来源:网络整理
导读:我正在数字海洋服务器的码头平台上部署一个简单的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 /

我正在数字海洋服务器的码头平台上部署一个简单的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 

// app.js

var express = require('express');
var PORT = 3000;
var app = express();
app.get('/',function (req,res) {
  res.send('Hello worldn');
});  
app.listen(PORT);
console.log('Running on http://localhost:' + PORT);

//码头文件

FROM dockerfile/nodejs
# Set the working directory
WORKDIR   /src
EXPOSE  3000
CMD ["/bin/bash"]

docker基本映像是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'
最佳答案
确保dns设置正确.我在Docker服务重新启动后遇到了一些问题.如果没有帮助,可能需要使用–dns 8.8.8.8码头开关.

重新启动码头服务:

>在systemd架构 – sudo systemctl重新启动docker
> boot2docker – boot2docker restart
> Docker Machine – docker-machine restart< machine_name>

此外,我做了类似的事情(nodejs图像),但是我已经使用了另一个基本图像,随时可以使用我从repo需要的任何东西.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读