docker错误集-CentOS环境

1、问题:WARNING: IPv4 forwarding is disabled. Networking will not work.

容器内无法访问外网,宿主机可以

原因:
“ default the ipv4 forwarding is not turned on in the image from docker to prevent any security vulnerabilities. ”

Docker处于安全考虑默认关闭该设置。

解决方案:

返回宿主机

echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf

systemctl restart network && systemctl restart docker

sysctl net.ipv4.ip_forward