docker容器访问不了外网

一、检查是否开启转发

cat /proc/sys/net/ipv4/ip_forward
0

开启转发

vim /etc/sysctl.conf
net.ipv4.ip_forward = 1
net.bridge.bridge-nf-call-ip6tables = 1
net.bridge.bridge-nf-call-iptables = 1
net.bridge.bridge-nf-call-arptables = 1

sysctl -p

二、检查docker启动时是否加载

iptables -L |grep -i docker

DOCKER-ISOLATION  all  --  anywhere             anywhere            
DOCKER     all  --  anywhere             anywhere            
DOCKER     all  --  anywhere             anywhere            
Chain DOCKER (2 references)
Chain DOCKER-ISOLATION (1 references)

没有上面上显示,则需要加载一下

vim /etc/systemd/system/docker.service 

ExecStart=/usr/bin/dockerd --iptables=true  #dockerd中加上--iptables=true

三、重启docker

systemctl daemon-reload
systemctl restart docker

----------------end

你可能感兴趣的:(docker,docker,容器)