我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
Docker运行-dns 8.8.8.8 base ping google.com
Docker运行base ping google.com
Sysctl -w net.ipv4。Ip_forward =1 -在主机和容器上
我得到的是未知主机google.com。Docker 0.7.0版本
什么好主意吗?
P.S. ufw也被禁用了
我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
Docker运行-dns 8.8.8.8 base ping google.com
Docker运行base ping google.com
Sysctl -w net.ipv4。Ip_forward =1 -在主机和容器上
我得到的是未知主机google.com。Docker 0.7.0版本
什么好主意吗?
P.S. ufw也被禁用了
当前回答
我不知道我在做什么,但这对我很有用:
OTHER_BRIDGE=br-xxxxx # this is the other random docker bridge (`ip addr` to find)
service docker stop
ip link set dev $OTHER_BRIDGE down
ip link set dev docker0 down
ip link delete $OTHER_BRIDGE type bridge
ip link delete docker0 type bridge
service docker start && service docker stop
iptables -t nat -A POSTROUTING ! -o docker0 -s 172.17.0.0/16 -j MASQUERADE
iptables -t nat -A POSTROUTING ! -o docker0 -s 172.18.0.0/16 -j MASQUERADE
service docker start
其他回答
如果你运行的Docker是无根的,并且遇到了这个问题,在安装过程中,iptables可能没有正确配置,主要是因为在Docker抱怨iptables时使用了——skip-iptables选项:
[ERROR] Missing system requirements. Run the following commands to
[ERROR] install the requirements and run this tool again.
[ERROR] Alternatively iptables checks can be disabled with --skip-iptables .
########## BEGIN ##########
sudo sh -eux <<EOF
# Load ip_tables module
modprobe ip_tables
EOF
########## END ##########
让我们检查一下这是否是问题所在:是否加载了ip_tables内核模块?
sudo modprobe ip_tables
如果没有输出,这个答案可能对您没有帮助(无论如何您都可以尝试)。否则,输出如下所示:
modprobe: FATAL: Module ip_tables not found in directory /lib/modules/5.18.9-200.fc36.x86_64
让我们来解决它!
首先,卸载Docker rootless(不需要通过systemctl停止服务,脚本会处理):
dockerd-rootless-setuptool.sh uninstall --skip-iptables
确保安装了iptables包,尽管它是由主要发行版默认提供的。
现在,让ip_tables模块对modprobe可见并安装它(多亏了这个):
sudo depmod
sudo modprobe ip_tables
现在,重新安装Docker rootless:
dockerd-rootless-setuptool.sh install
如果它不打扰iptables,你就完成了,问题应该得到解决。不要忘记启用服务(即systemctl enable——user——now docker)!
对我来说,这是iptables的转发规则。由于某种原因,下面的规则,当与docker的iptables规则结合在一起时,导致所有来自容器的出站流量都到达localhost:8080:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
iptables -t nat -I OUTPUT -p tcp -d 127.0.0.1 --dport 80 -j REDIRECT --to-ports 8080
为子孙后代分享一个简单而有效的解决方案。当我们运行docker容器时,没有显式地提到——network标志,它连接到它的默认网桥网络,这禁止连接到外部世界。为了解决这个问题,我们必须创建自己的网桥网络(用户定义的网桥),并且必须使用docker run命令显式地提到它。
docker network create --driver bridge mynetwork
docker run -it --network mynetwork image:version
唯一能在我的电脑上工作的东西(8.8.8.8不起作用)
找出本地机器中使用的DNS:
$ netstat -ntpl | grep :53
tcp 0 0 10.194.128.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 192.168.122.1:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.2.1:53 0.0.0.0:* LISTEN -
修改docker配置sudo vim /etc/docker/daemon.Json基于上述信息在您自己的计算机上
{
"dns": ["192.168.122.1","10.194.128.1"]
}
重启码头工人
sudo ip link delete docker0
sudo systemctl restart docker
只是在这里添加这个,以防有人在运行docker的virtualbox容器中遇到这个问题。我将virtualbox网络重新配置为桥接而不是nat,问题就消失了。