我在我的 Ubuntu 主机上使用 docker,并且想用一些开发包构建一个服装图像。
每当我跑步时
docker run -it 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... Done
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'
W: Some index files failed to download. They have been ignored, or old ones used instead.
输出docker run -it ubuntu more /etc/resolv.conf
是
search company.com
nameserver 8.8.8.8
nameserver 8.8.4.4
注意:company.com 是我的组织域名
输出docker network inspect bridge
是
[
{
"Name": "bridge",
"Id": "ee1a3e8cac6fdc0be630ae027957345b63977b6bb74cec04a9200f1ad8f895f7",
"Created": "2017-02-09T21:46:05.235449663+05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.17.0.0/16",
"Gateway": "172.17.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Containers": {},
"Options": {
"com.docker.network.bridge.default_bridge": "true",
"com.docker.network.bridge.enable_icc": "true",
"com.docker.network.bridge.enable_ip_masquerade": "true",
"com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
"com.docker.network.bridge.name": "docker0",
"com.docker.network.driver.mtu": "1500"
},
"Labels": {}
}
]
答案1
对我有用的是这指导。
从https://stackoverflow.com/a/40516974(YOUR_DNS_IP_HERE 是我添加的)
将其放入 /etc/docker/daemon.json:
{ "dns": ["YOUR_DNS_IP_HERE", "YOUR_DNS_IP_HERE"] }
退出根目录:
exit
现在重新启动docker:
sudo service docker restart
确认:
现在检查添加 /etc/docker/daemon.json 文件是否允许您将“google.com”解析为 IP 地址:
docker run busybox nslookup google.com