apt-get在基于Debian和Ubuntu的Docker镜像中失败

尝试在Debian或Ubuntu docker镜像中运行apt-get更新时出现这个奇怪的错误:

root@60931d7602e1:/# apt-get update Ign http://security.debian.org jessie/updates InRelease Ign http://httpredir.debian.org jessie InRelease Ign http://security.debian.org jessie/updates Release.gpg Ign http://httpredir.debian.org jessie-updates InRelease Ign http://security.debian.org jessie/updates Release Ign http://httpredir.debian.org jessie Release.gpg Err http://security.debian.org jessie/updates/main amd64 Packages Ign http://httpredir.debian.org jessie-updates Release.gpg Err http://security.debian.org jessie/updates/main amd64 Packages Ign http://httpredir.debian.org jessie Release Err http://security.debian.org jessie/updates/main amd64 Packages Ign http://httpredir.debian.org jessie-updates Release Err http://security.debian.org jessie/updates/main amd64 Packages Err http://security.debian.org jessie/updates/main amd64 Packages 404 NOT FOUND [IP: 149.20.20.6 80] Err http://httpredir.debian.org jessie/main amd64 Packages 404 NOT FOUND [IP: 176.9.184.93 80] Err http://httpredir.debian.org jessie-updates/main amd64 Packages 404 NOT FOUND [IP: 176.9.184.93 80] W: Failed to fetch http://security.debian.org/dists/jessie/updates/main/binary-amd64/Packages 404 NOT FOUND [IP: 149.20.20.6 80] W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie/main/binary-amd64/Packages 404 NOT FOUND [IP: 176.9.184.93 80] W: Failed to fetch http://httpredir.debian.org/debian/dists/jessie-updates/main/binary-amd64/Packages 404 NOT FOUND [IP: 176.9.184.93 80] E: Some index files failed to download. They have been ignored, or old ones used instead. 

我检查了url并不存在,它应该是.gz或.bz2。 它只发生在一个主机服务器上(运行Ubuntu),到目前为止,在boot2docker和Debian中工作正常。

我发现这是由于我们在将端口80redirect到本地主机端口5000的服务器上build立的IP表规则。它被意外地设置在两个方向上。

apt-get请求URL没有.gz / .bz2,因为它已经失败了。

您收到由于您的实例的networking问题而Failed to fetch错误。 最有可能的是高速caching代理或坏镜子。 解决这个问题的最简单方法是使用VPN连接从其他地理位置获取软件包更新,这将触发不同的镜像。