前言

容器默认使用桥接模式连接到宿主机的虚拟网卡
,如果需要连接🔗到互联网,那么需要哪些设置呢

设置

参考:

https://docs.docker.com/network/bridge/

官方文档说要开启宿主机的ip转发并清空防火墙的设置:

Enable forwarding from Docker containers to the outside world
By default, traffic from containers connected to the default bridge network is not forwarded to the outside world. To enable forwarding, you need to change two settings. These are not Docker commands and they affect the Docker host’s kernel.

Configure the Linux kernel to allow IP forwarding.

$ sysctl net.ipv4.conf.all.forwarding=1

Change the policy for the iptables FORWARD policy from DROP to ACCEPT.

$ sudo iptables -P FORWARD ACCEPT

These settings do not persist across a reboot, so you may need to add them to a start-up script.

但是这个设置重启后就失效了,你可以使用root 权限去修改对应的系统文件 , 例如

vim /etc/sysctl.conf

标签: etc, 文档, settings, 文件, sudo, 前言, vim, the, default, root, add, sysctl, 模式, 对应, 设置, forwarding, docker, iptables

知识共享许可协议
本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可。

发送一条友善的评论

  • 目录