[英]npm install inside docker build
I am dockerising a nodejs
application on ubuntu 17.10
locally with Oracle VM Virtualbox. 我正在使用Oracle VM Virtualbox在
ubuntu 17.10
本地化一个nodejs
应用程序。
I have mentioned following steps in Dockerfile: 我在Dockerfile中提到了以下步骤:
FROM node:7
WORKDIR /home/ubuntu/Downloads/nodejs/workdirectory
COPY package.json /home/ubuntu/Downloads/nodejs/workdirectory
RUN npm install
COPY . /home/ubuntu/Downloads/nodejs/workdirectory
CMD node index.js
EXPOSE 8081
I am facing following error: 我面临以下错误:
ubuntu@ubuntu-VirtualBox:~/Downloads/nodejs/application$ sudo docker build -t acc/nodejsapp2:1.0 .
Sending build context to Docker daemon 4.096kB
Step 1/7 : FROM node:7
---> d9aed20b68a4
Step 2/7 : WORKDIR /home/ubuntu/Downloads/nodejs/workdirectory
---> Using cache
---> 0efd4825ed8f
Step 3/7 : COPY package.json /home/ubuntu/Downloads/nodejs/workdirectory
---> Using cache
---> 5c1ef3d889b5
Step 4/7 : RUN npm install
---> Running in f0bbfa9920cb
npm info it worked if it ends with ok
npm info using npm@4.2.0
npm info using node@v7.10.1
npm info attempt registry request try #1 at 8:46:04 AM
npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #2 at 8:46:54 AM
npm http request GET https://registry.npmjs.org/express
npm info retry will retry, error on last attempt: Error: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm info attempt registry request try #3 at 8:48:34 AM
npm http request GET https://registry.npmjs.org/express
npm ERR! Linux 4.13.0-36-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v7.10.1
npm ERR! npm v4.2.0
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR! <https://github.com/npm/npm/issues>
npm ERR! Please include the following file with any support request:
npm ERR! /root/.npm/_logs/2018-03-02T08_49_14_320Z-debug.log
The command '/bin/sh -c npm install' returned a non-zero code: 1
As per many articles in stackoverflow, 根据stackoverflow中的许多文章,
1)I have made changes in etc/hosts of Ubuntu as follows: 1)我在Ubuntu的etc / hosts中进行了如下更改:
127.0.0.1 localhost
127.0.1.1 ubuntu-VirtualBox
151.101.16.162 registry.npmjs.org
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
2)I also made entry in /etc/default/docker as: 2)我还在/ etc / default / docker中输入如下内容:
DOCKER_OPTS="--dns 151.101.16.162"
It is not working in docker build. 它在docker build中不起作用。 How can i proceed with steps to rectify it?
我如何进行纠正步骤?
Kindly follow the following steps for rectifying the error in Ubuntu occurred in above: 请按照以下步骤纠正上述Ubuntu中发生的错误:
1)Find out the ip of the Ethernet network by using ifconfig. 1)使用ifconfig找出以太网的IP。
enp0s4: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet **10.X.X.XX** netmask 255.255.255.0 broadcast 10.8.89.898
2)Create a new network and enable Default IP when binding container ports and mention the above ip address. 2)创建一个新的网络,并在绑定容器端口时启用默认IP,并提及上述ip地址。
docker network create -o "com.docker.network.bridge.host_binding_ipv4"="10.X.X.XX" my-network
3)Use this newly created network to build the docker image: 3)使用这个新创建的网络来构建docker镜像:
docker build --network my-network -t hello-world .
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.