有人可以帮助我在我的 docker 容器中使用 apt-get 吗?每当我尝试在我的 docker 容器中运行任何 apt-get 命令时,该命令都会失败。我正在运行 Docker 版本 1.1.1,在 ubuntu 12.04 上构建 bd609d2。
当我这样做时
$ sudo docker run -i -t ubuntu:14.04 /bin/bash
# apt-get update
我收到错误提示
Could not resolve 'archive.ubuntu.com'
我尝试在/etc/default/docker 中取消注释下面的行
DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"
但我仍然无法 ping google.com
ping: unknown host
我确认容器正在使用 dns 服务器 8.8.8.8 和 8.8.4.4
root@0baa87fc6322:/# cat /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
而且我可以 ping 两台服务器,所以我很确定防火墙不只是丢弃我的数据包。
对此的任何帮助将不胜感激!
谢谢!
最佳答案
感谢您的所有帮助!我发现这是一个 dns 问题,而且是因为防火墙。在搜索了更多之后,我发现了在搜索“docker apt-get fail”时无法找到的这个问题
Docker - Network calls fail during image build on corporate network
他的问题与我的相似,解决方案帮助我让它发挥作用。 我已经复制了他的解决方案,供以后发现此问题的任何人使用。
Those Google servers weren't accessible from behind our firewall, which is why we couldn't resolve any URLs.
The fix is to tell Docker which DNS servers to use. This fix depends on how you installed Docker: Ubuntu Package
If you have the Ubuntu package installed, edit /etc/default/docker and add the following line:
DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"
You can add as many DNS servers as you want to this config. Once you've edited this file you'll want to restart your Docker service:
sudo service docker restart
Binaries
If you've installed Docker via the binaries method (i.e. no package), then you set the DNS servers when you start the Docker daemon:
sudo docker -d -D --dns --dns &
关于Docker apt-get 更新失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24832972/