运行Docker容器时,主机上没有网络

时间:2016-01-10 20:22:12

标签: networking docker host wlan

我在Arch Linux机器上,使用此命令运行容器时主机上没有网络:

docker run jenkins

停止Docker后,网络又回来了。 非常欢迎任何建议。

编辑:

似乎在使用-p选项运行并提供80以外的其他端口时,网络可用几分钟,然后再次丢失。

**> docker version**

Client:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.5.1
 Git commit:   a34a1d5-dirty
 Built:        Sun Nov 22 00:15:15 UTC 2015
 OS/Arch:      linux/amd64

Server:
 Version:      1.9.1
 API version:  1.21
 Go version:   go1.5.1
 Git commit:   a34a1d5-dirty
 Built:        Sun Nov 22 00:15:15 UTC 2015
 OS/Arch:      linux/amd64

**> docker info**

Containers: 31
Images: 57
Server Version: 1.9.1
Storage Driver: devicemapper
 Pool Name: docker-8:5-548039-pool
 Pool Blocksize: 65.54 kB
 Base Device Size: 107.4 GB
 Backing Filesystem: 
 Data file: /dev/loop0
 Metadata file: /dev/loop1
 Data Space Used: 3.584 GB
 Data Space Total: 107.4 GB
 Data Space Available: 7.741 GB
 Metadata Space Used: 7.496 MB
 Metadata Space Total: 2.147 GB
 Metadata Space Available: 2.14 GB
 Udev Sync Supported: true
 Deferred Removal Enabled: false
 Deferred Deletion Enabled: false
 Deferred Deleted Device Count: 0
 Data loop file: /var/lib/docker/devicemapper/devicemapper/data
 Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
 Library Version: 1.02.113 (2015-12-05)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 4.2.5-1-ARCH
Operating System: Arch Linux (containerized)
CPUs: 4
Total Memory: 7.709 GiB
Name: arch
ID: OF5Y:H7O4:M4R6:GCF6:NSEU:LNG6:K7NV:FJDM:DUVI:6KOM:LTRB:EUPP

> iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
DOCKER     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere             ctstate RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain DOCKER (1 references)
target     prot opt source               destination         

2 个答案:

答案 0 :(得分:3)

可能是您的泊坞主机网络设置与Docker不匹配。试试你可以在Docker文档中找到的Arch Linux specific instructions regarding networking

  

如果您使用systemd-network版本220或更高版本手动配置网络,请为您提供容器   从Docker开始可能无法访问您的网络。从版本220开始,转发   给定网络的设置(net.ipv4.conf.<interface>.forwarding)默认为 off 。这个设置   防止IP转发。它也与Docker冲突,它启用了net.ipv4.conf.all.forwarding   在容器内设置。

     

要解决此问题,请在您的Docker主机添加&gt;上编辑<interface>.network中的/etc/systemd/network/文件。以下块:

[Network]
...
IPForward=kernel
...
     

此配置允许按预期从容器进行IP转发。

还试一试关于Docker的Arch Linux wiki的docker0 Bridge gets no IP / no internet access in containers部分:

  

Docker自行启用IP转发,但默认情况下,systemd会覆盖相应的sysctl设置。下列   禁用此覆盖(适用于所有接口):

# cat > /etc/systemd/network/ipforward.network <<EOF
[Network]
IPForward=ipv4
EOF

# cat > /etc/systemd/network/99-docker.conf <<EOF
net.ipv4.ip_forward = 1
EOF

# sysctl -w net.ipv4.ip_forward=1
     

最后重启systemd-networkd和docker服务。

答案 1 :(得分:1)

解决方案是使用以下内容创建或编辑/etc/connman/main.conf:

[General]
NetworkInterfaceBlacklist=vmnet,vboxnet,virbr,ifb,docker,veth,eth,wlan

然后重启connman。

作为described here