CentOS 7 docker build 时错误 IPv4 forwarding is disabled.
环境 CentOS 7 腾讯云
构建 Docker 镜像时
docker build -t tumobi/nideshop-docker .
出现错误
Step 4/8 : RUN npm i --production
---> [Warning] IPv4 forwarding is disabled. Networking will not work.
---> Running in e0612a6b5904
npm ERR! code EAI_AGAIN
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/think-model failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org:443
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2018-11-26T03_02_04_059Z-debug.log
解决方法
vim /etc/sysctl.conf
net.ipv4.ip_forward = 0 改为 net.ipv4.ip_forward = 1
重启网卡服务
systemctl restart network
查看是否生效
sysctl net.ipv4.ip_forward
值为 1 则表示成功开启
net.ipv4.ip_forward = 1