Docker apt-get 更新失败 [英] Docker apt-get update fails

查看:100
本文介绍了Docker apt-get 更新失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我在我的 docker 容器中使用 apt-get 吗?每当我尝试在我的 docker 容器中运行任何 apt-get 命令时,该命令都会失败.我正在运行 Docker 1.1.1 版,在 ubuntu 12.04 上构建 bd609d2.

Can somebody help me get apt-get working in my docker container? Whenever I try running any apt-get command in my docker container, the command fails. I'm running Docker version 1.1.1, build bd609d2 on ubuntu 12.04.

当我这样做

$ sudo docker run -i -t ubuntu:14.04 /bin/bash
# apt-get update

我收到错误提示

无法解析archive.ubuntu.com"

Could not resolve 'archive.ubuntu.com'

我尝试在/etc/default/docker 中取消注释以下行

I tried uncommenting the line below in /etc/default/docker

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

DOCKER_OPTS="--dns 8.8.8.8 --dns 8.8.4.4"

但我仍然无法 ping google.com

but I still can't ping google.com

ping:未知主机

我确认容器正在使用 dns 服务器 8.8.8.8 和 8.8.4.4

I confirmed that the container is using the dns servers 8.8.8.8 and 8.8.4.4

root@0baa87fc6322:/# cat/etc/resolv.conf

root@0baa87fc6322:/# cat /etc/resolv.conf

域名服务器 8.8.8.8

nameserver 8.8.8.8

域名服务器 8.8.4.4

nameserver 8.8.4.4

而且我可以 ping 两台服务器,所以我很确定防火墙不只是丢弃我的数据包.

and I'm able to ping both servers so I'm pretty sure that a firewall isn't just dropping my packets.

对此的任何帮助将不胜感激!

Any help with this would be appreciated!

谢谢!

推荐答案

感谢您的帮助!我发现这是一个 dns 问题,这是因为防火墙.在搜索了更多之后,我发现了这个问题,而我在搜索 'docker apt-get fail' 时找不到这个问题

Thanks for all your help! I found out it was a dns problem and that it was because of a firewall. After searching some more I found this question that I wasn't able to find while searching 'docker apt-get fail'

Docker - 图像构建期间网络调用失败企业网络

他的问题与我的相似,解决方案帮助我解决了问题.我已经为将来发现此问题的任何人复制了他的解决方案.

His problem was similar to mine and the solution helped me get it working. I've copied over his solution for anybody that finds this question in the future.

无法从我们的防火墙后面访问那些 Google 服务器,这就是我们无法解析任何 URL 的原因.

Those Google servers weren't accessible from behind our firewall, which is why we couldn't resolve any URLs.

解决方法是告诉 Docker 使用哪些 DNS 服务器.此修复取决于您安装 Docker 的方式:Ubuntu 包

The fix is to tell Docker which DNS servers to use. This fix depends on how you installed Docker: Ubuntu Package

如果您安装了 Ubuntu 软件包,请编辑/etc/default/docker 并添加以下行:

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>"

DOCKER_OPTS="--dns <your_dns_server_1> --dns <your_dns_server_2>"

您可以在此配置中添加任意数量的 DNS 服务器.编辑此文件后,您将需要重新启动 Docker 服务:

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

sudo service docker restart

二进制文件

如果你已经通过二进制方法安装了 Docker(即没有包),那么你在启动 Docker 守护进程时设置了 DNS 服务器:

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 &

sudo docker -d -D --dns --dns &

这篇关于Docker apt-get 更新失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆