Docker Debian apt从服务器读取错误
看起来,apt-get存在与存储库服务器连接的问题。 我想这可能是兼容性问题,正如这里所提到的,然而,提出的apt-get clean
解决scheme对我来说并不适用。 另外我很惊讶,如果是这样的话,没有更多的人有我的问题。
MWE
Dockerfile
FROM debian:jessie RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommends \ git
$ docker build . docker build . Sending build context to Docker daemon 2.048 kB Step 0 : FROM debian:jessie ---> 4a5e6db8c069 Step 1 : RUN apt-get clean && apt-get update && apt-get install -y --no-install-recommends git ---> Running in 43b93e93feab Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB] ... some omitted ... Get:6 http://httpredir.debian.org jessie-updates/main amd64 Packages [3614 B] Fetched 9552 kB in 7s (1346 kB/s) Reading package lists... Reading package lists... Building dependency tree... Reading state information... The following extra packages will be installed: ... some omitted ... 0 upgraded, 26 newly installed, 0 to remove and 0 not upgraded. Need to get 13.2 MB of archives. After this operation, 64.0 MB of additional disk space will be used. Get:1 http://security.debian.org/ jessie/updates/main libgnutls-deb0-28 amd64 3.3.8-6+deb8u2 [694 kB] ... some omitted ... Get:5 http://httpredir.debian.org/debian/ jessie/main libnettle4 amd64 2.7.1-5 [176 kB] Err http://httpredir.debian.org/debian/ jessie/main libffi6 amd64 3.1-2+b2 Error reading from server. Remote end closed connection [IP: 176.9.184.93 80] ... some omitted ... Get:25 http://httpredir.debian.org/debian/ jessie/main git amd64 1:2.1.4-2.1 [3624 kB] Fetched 13.2 MB in 10s (1307 kB/s) E: Failed to fetch http://httpredir.debian.org/debian/pool/main/libf/libffi/libffi6_3.1-2+b2_amd64.deb Error reading from server. Remote end closed connection [IP: 176.9.184.93 80] E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing? The command '/bin/sh -c apt-get clean && apt-get update && apt-get install -y --no-install-recommends git' returned a non-zero code: 100
请注意,我也在这里发布了一个不同的问题。 我相信这是无关的,但实际上可能是这样。
httpredir.debian.org镜像是“神奇的”,因为它将负载平衡和地理ip你透明地提高性能和可用性。 因此,我会立即怀疑这是造成你的问题,或者至less是首先排除的问题。
我会检查你是否可以:
-
仍然重现问题;
httpredir.debian.org
会从内部列表中扔出“坏”的镜像,所以你的问题可能是暂时的。 -
使用不同的非
httpredir.debian.org
镜像重现问题。 尝试类似ftp.de.debian.org
。 如果它能和这个镜像一起工作,请联系httpredir.debian.org
维护者并向他们报告问题。 他们相当敏感,并开放bug报告。
对于有这个问题的人来说,这是我试图通过每当Dockerfile被构build时用单个工作域换出httpredir
来“解决”问题:
FROM debian:je... # Insert this line before "RUN apt-get update" to dynamically # replace httpredir.debian.org with a single working domain # in attempt to "prevent" the "Error reading from server" error. RUN sed -i "s/httpredir.debian.org/`curl -s -D - http://httpredir.debian.org/demo/debian/ | awk '/^Link:/ { print $2 }' | sed -e 's@<http://\(.*\)/debian/>;@\1@g'`/" /etc/apt/sources.list # Continue with your apt-get update... RUN apt-get update...
这个命令的作用是:
- 从build筑机器上find
http://httpredir.debian.org/demo/debian/
,从debian演示页面获取头文件(-s
是沉默的,不输出。--D
是转储头文件) - 提取标题,find
Link
标题片段。 这包含httpredir推荐的最佳路由。 - 最后的
sed -e ...
是在步骤2中提取链接的域名。 - 最后,步骤3中find的域将被送入全局sed命令,并replace
/etc/apt/sources.list
find的域httpredir.debian.org
。
这不是一个修复,而是一个简单的黑客(大大)减less失败的机会。 而且,如果看起来很奇怪,请原谅我,因为这是我的处女sed&pipe道的尝试。
编辑
在旁边注意,如果它select的域名太慢或没有响应它应该,您可能需要手动做
-
访问http://httpredir.debian.org/demo.html ,你应该看到像
http://......./debian/
这样的链接。 例如,在写作的时候,我看到http://mirrors.tuna.tsinghua.edu.cn/debian/
-
而不是长期
RUN sed -i....
命令,而不是使用:RUN sed -i "s/httpredir.debian.org/mirrors.tuna.tsinghua.edu.cn/" /etc/apt/sources.list
我在apt-get update
行之前添加了apt-get clean
到我的dockerfile,似乎已经完成了。
我想我无法知道是否是额外的命令,或者如果是运气,修复了我的构build,但我从https://github.com/CGAL/cgal-testsuite-dockerfiles/issues/ 19
对于那些访问相似的问题,在docker build
使用--no-cache
标志可能会有所帮助。 类似的问题(虽然不是这个确切的问题)可能发生,如果apt-get更新是旧的,而不是被召回起诉caching。
没有足够的声望评论以前的答案,所以我会(混淆)添加一个新的答案:
- 我不认为单个镜像的硬编码是一个真正可行的解决scheme,因为例如在这里看到的,有一个原因debian实现了整个httpredir的东西 – 镜像倒塌或过时。
- 我已经处理了这个问题很多次了,日志总是显示docker实际上正在运行apt-get命令,这意味着–no-cache不太可能修复它 – 这只是如果你重build,httpredir可能会select一个不同的镜像,即使你没有改变你的docker文件中的任何内容,这个构build也是可行的。