Docker Debian apt 从服务器读取错误

标签 docker debian apt-get

似乎 apt-get 与存储库服务器的连接存在问题。我想这可能是兼容性问题,如 here 所述,但是 apt-get clean 的建议解决方案对我不起作用。我也很惊讶,如果是这样的话,没有更多的人遇到我的问题。

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

请注意,我还发布了 here有一个不同的问题。我认为这无关紧要,但实际上很可能是。

最佳答案

对于遇到此问题的人,这是我尝试通过在构建 Dockerfile 时将 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...

这个命令的作用是:

  1. 从构建机器 curl http://httpredir.debian.org/demo/debian/ 以从 debian 演示页面获取 header (-s 是静默的,不输出。-D是转储头文件)
  2. 提取 header ,找到 Link header 片段。这包含了 httpredir 推荐的最佳路线。
  3. 最后一个sed -e ...是在步骤2中提取出链接的域名。
  4. 最后,将步骤 3 中找到的域输入到全局 sed 命令中,并替换 /etc/apt/sources.list 中找到的域 httpredir.debian.org .

这不是一个修复,而是一个简单的 hack,以(大大)减少构建失败的机会。而且......如果它看起来很奇怪,请原谅我,因为这是我的处女 sed 和管道尝试。

编辑

附带说明,如果它选择的域太慢或没有响应,您可能需要手动完成

  1. 访问 http://httpredir.debian.org/demo.html ,您应该会在那里看到一个类似 http://......./debian/ 的链接。比如我在写的时候看到了http://mirrors.tuna.tsinghua.edu.cn/debian/

  2. 不要使用长的 RUN sed -i.... 命令,而是使用以下命令:

    RUN sed -i "s/httpredir.debian.org/mirrors.tuna.tsinghua.edu.cn/" /etc/apt/sources.list
    

关于Docker Debian apt 从服务器读取错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32304631/

相关文章:

ubuntu - 创建 Debian 软件包失败

git - Ubuntu/DigitalOcean - 无法获取软件包以在全新安装时安装 git

proxy - Ubuntu 16.04 apt-get 无法通过代理工作

docker - 如何在 convox 中使用本地 docker 镜像?

node.js - Prisma 创建数据库但随后表示无法连接到该数据库

linux - 在 Debian OS 中安装应用程序

python - Virtualenv 和 debian 中的代码位置

ubuntu - 通过apt-get安装后如何告诉cmake找到boost?

docker - 将今天的日期设置为环境变量

apache-spark - Spark Job Server是否必须与Spark Master部署在同一主机上?