我让它正常工作,但现在它停了。我尝试了以下命令,但没有效果:
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也被禁用了
当前回答
经过几个小时的努力,我终于解决了问题
问题是linux使用旧版本的libseccomp2
获取签名密钥以验证新包,否则将无法安装
rpi ~$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 04EE7237B7D453EC 648ACFD622F3D138
将Buster后台端口存储库添加到apt sources.list
rpi ~$ echo 'deb http://httpredir.debian.org/debian buster-backports main contrib non-free' | sudo tee -a /etc/apt/sources.list.d/debian-backports.list
rpi ~$ sudo apt update
rpi ~$ sudo apt install libseccomp2 -t buster-backports
在这次尝试之后
rpi ~$ docker run -it --rm alpine:3.15.0
(alpine shell)# apk update
Apk更新将获取,因此您连接到互联网
我在用
Linux raspberrypi 5.10.63-v7l+ #1496 SMP Wed Dec 1 15:58:56 GMT 2021 armv7l GNU/Linux
您可以使用uname -a进行检查
其他回答
对我来说,是主机的防火墙。我必须在主机的防火墙上允许DNS。并且在更改主机防火墙设置后不得不重新启动docker。
在我的例子中,由于一些未知的原因,docker被配置为不生成网络所需的iptables规则容器。docker容器只能ping主机,没有其他功能。这里的大多数答案都没有帮助;重新创建桥或重新启动服务改变了任何东西。
但后来,在一次偶然的机会下,我发现了以下内容:
$ cat /etc/docker/daemon.json
{"iptables": false}
我删除了/etc/docker/daemon.文件Json并重新启动守护进程(默认是创建iptables规则)。这解决了网络问题。
下面是修复前的iptables规则:
$ iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
现在,iptables规则修复后:
$ iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy DROP)
target prot opt source destination
DOCKER-USER all -- 0.0.0.0/0 0.0.0.0/0
DOCKER-ISOLATION-STAGE-1 all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
DOCKER all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0 ctstate RELATED,ESTABLISHED
DOCKER all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
ACCEPT all -- 0.0.0.0/0 0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain DOCKER (2 references)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 172.17.0.2 tcp dpt:8443
Chain DOCKER-ISOLATION-STAGE-1 (1 references)
target prot opt source destination
DOCKER-ISOLATION-STAGE-2 all -- 0.0.0.0/0 0.0.0.0/0
DOCKER-ISOLATION-STAGE-2 all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
Chain DOCKER-ISOLATION-STAGE-2 (2 references)
target prot opt source destination
DROP all -- 0.0.0.0/0 0.0.0.0/0
DROP all -- 0.0.0.0/0 0.0.0.0/0
RETURN all -- 0.0.0.0/0 0.0.0.0/0
Chain DOCKER-USER (1 references)
target prot opt source destination
RETURN all -- 0.0.0.0/0 0.0.0.0/0
我使用DOCKER_OPTS="——dns 8.8.8.8",后来发现我的容器不能直接访问互联网,但可以访问我的公司内部网。我把DOCKER_OPTS改为如下:
DOCKER_OPTS="--dns <internal_corporate_dns_address"
替换internal_corporate_dns_address与我们的DNS的IP地址或FQDN和重启docker使用
sudo service docker restart
然后生成我的容器并检查它是否可以访问互联网。
对我来说,使用centos 7.4,这不是/etc/resolve.conf, iptables, iptables NAT规则或docker本身的问题。问题是主机缺少包bridge-utils, docker需要使用brctl命令来构建桥。Yum安装-y bridge-utils并重新启动docker,解决问题。
重启docker的方法不是手动,而是使用service或systemctl命令:
service docker restart
or
systemctl restart docker