Docker容器中没有Internet连接

时间:2016-10-03 09:17:22

标签: ubuntu docker internet-connection

我无法在任何Docker容器中执行任何需要互联网连接的命令。

使用:

docker run ubuntu /bin/echo 'Hello world'

不起作用:

docker run ubuntu apt-get update

Err:1 http://archive.ubuntu.com/ubuntu xenial InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:2 http://archive.ubuntu.com/ubuntu xenial-updates InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Err:3 http://archive.ubuntu.com/ubuntu xenial-security InRelease
  Temporary failure resolving 'archive.ubuntu.com'
Reading package lists...
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-updates/InRelease  Temporary failure resolving 'archive.ubuntu.com'
W: Failed to fetch http://archive.ubuntu.com/ubuntu/dists/xenial-security/InRelease  Temporary failure resolving 'archive.ubuntu.com'

pipping类似。

我在Ubuntu 16.04上,没有使用防火墙或公司代理服务器,并试图重启Docker。不使用docker-machine或boot2docker。

2 个答案:

答案 0 :(得分:0)

Got answer on SuperUser:

pkill docker
iptables -t nat -F
ifconfig docker0 down
brctl delbr docker0
docker -d

“它将强制docker重新创建网桥并重新启动所有网络规则”

答案 1 :(得分:0)

就我而言,仅删除docker0接口是不够的,j我也必须删除br接口(请参阅ip link)。

对于使用systemd的Linux用户:

#!/usr/bin/env sh
if ! [ "$(id -u)" = "0" ]; then
   echo "Run as root please."
   exit 1
fi

# not sure if this is needed
iptables -t nat -F

# stop docker
systemctl stop docker

# stop the `br-...` interfaces.
ip link | awk -F': ' '/: br-/ {print $2}' | xargs -I % ifconfig % down
# ... and remove them
ip link | awk -F': ' '/: br-/ {print $2}' | xargs brctl delbr

# stop the docker0 interface
ifconfig docker0 down
# ... and remove it
brctl delbr docker0

# start docker again, this will re-create the docker0 interface.
systemctl start docker
相关问题