Dockerfile 中安装 Criu 并解决 TLS 连接错误

在 Dockerfile 中安装 Criu 时,可能会遇到以下错误:

FROM base AS criu
ARG DEBIAN_FRONTEND
ENV http_proxy=http://192.168.44.37:7890
ENV https_proxy=https://192.168.44.37:7890
ADD --chmod=0644 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/Release.key /etc/apt/trusted.gpg.d/criu.gpg.asc
RUN --mount=type=cache,sharing=locked,id=moby-criu-aptlib,target=/var/lib/apt \
    --mount=type=cache,sharing=locked,id=moby-criu-aptcache,target=/var/cache/apt \
        echo 'deb https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/ /' > /etc/apt/sources.list.d/criu.list \
        && apt update \
        && apt install -y --no-install-recommends criu \
        && install -D /usr/sbin/criu /build/criu
报错> [criu 2/2] RUN --mount=type=cache,sharing=locked,id=moby-criu-aptlib,target=/var/lib/apt     --mount=type=cache,sharing=locked,id=moby-criu-aptcache,target=/var/cache/apt         echo 'deb https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/ /' > /etc/apt/sources.list.d/criu.list         && apt update         && apt install -y --no-install-recommends criu         && install -D /usr/sbin/criu /build/criu:

#0 2.068 

#0 2.068 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

#0 2.068 

#0 2.104 Err:1 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11  InRelease

#0 2.104   Could not handshake: The TLS connection was non-properly terminated. [IP: 192.168.44.37 7890]

#0 2.252 Hit:2 http://deb.debian.org/debian bullseye InRelease

#0 2.293 Hit:3 http://deb.debian.org/debian-security bullseye-security InRelease

#0 3.930 Hit:4 http://deb.debian.org/debian bullseye-updates InRelease

#0 4.032 Reading package lists...

#0 4.485 Building dependency tree...

#0 4.578 W: Failed to fetch https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/InRelease  Could not handshake: The TLS connection was non-properly terminated. [IP: 192.168.44.37 7890]

#0 4.578 W: Some index files failed to download. They have been ignored, or old ones used instead.

#0 4.578 16 packages can be upgraded. Run 'apt list --upgradable' to see them.

#0 4.603 

#0 4.603 WARNING: apt does not have a stable CLI interface. Use with caution in scripts.

#0 4.603 

#0 4.610 Reading package lists...

#0 5.008 Building dependency tree...

#0 5.225 The following additional packages will be installed:

#0 5.225   libnet1 libnl-3-200 libprotobuf-c1 libprotobuf23 python3-pkg-resources

#0 5.225   python3-protobuf python3-six

#0 5.226 Suggested packages:

#0 5.226   python3-setuptools

#0 5.226 Recommended packages:

#0 5.226   iproute2 | iproute

#0 5.284 The following NEW packages will be installed:

#0 5.284   criu libnet1 libnl-3-200 libprotobuf-c1 libprotobuf23 python3-pkg-resources

#0 5.284   python3-protobuf python3-six

#0 5.363 0 upgraded, 8 newly installed, 0 to remove and 16 not upgraded.

#0 5.363 Need to get 2315 kB of archives.

#0 5.363 After this operation, 11.1 MB of additional disk space will be used.

#0 5.363 Err:1 https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11  criu 3.17.1-1

#0 5.363   Could not handshake: The TLS connection was non-properly terminated. [IP: 192.168.44.37 7890]

#0 5.375 Get:2 http://deb.debian.org/debian bullseye/main amd64 libprotobuf23 amd64 3.12.4-1 [892 kB]

#0 7.015 Get:3 http://deb.debian.org/debian bullseye/main amd64 python3-pkg-resources all 52.0.0-4 [190 kB]

#0 7.167 Get:4 http://deb.debian.org/debian bullseye/main amd64 python3-six all 1.16.0-2 [17.5 kB]

#0 7.232 Get:5 http://deb.debian.org/debian bullseye/main amd64 python3-protobuf amd64 3.12.4-1 [382 kB]

#0 8.326 Get:6 http://deb.debian.org/debian bullseye/main amd64 libnet1 amd64 1.1.6+dfsg-3.1 [60.4 kB]

#0 8.410 Get:7 http://deb.debian.org/debian bullseye/main amd64 libnl-3-200 amd64 3.4.0-1+b1 [63.6 kB]

#0 9.589 Get:8 http://deb.debian.org/debian bullseye/main amd64 libprotobuf-c1 amd64 1.3.3-1+b2 [27.0 kB]

#0 9.611 Fetched 1632 kB in 4s (378 kB/s)

#0 9.611 E: Failed to fetch https://download.opensuse.org/repositories/devel:/tools:/criu/Debian_11/./amd64/criu_3.17.1-1_amd64.deb  Could not handshake: The TLS connection was non-properly terminated. [IP: 192.168.44.37 7890]

#0 9.611 E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

这个错误通常是因为代理设置问题导致的。

解决方法

1. 检查代理设置

确保 Dockerfile 中设置的代理地址和端口正确,并且代理服务器可以正常工作。

2. 使用 --no-check-certificate

在 Dockerfile 中,--no-check-certificate 应该配置在使用 curl 或 wget 等工具下载文件时的命令中,例如:

RUN curl --no-check-certificate -o file.tar.gz https://example.com/file.tar.gz

或者

RUN wget --no-check-certificate https://example.com/file.tar.gz

3. 更新 apt 源

如果问题仍然存在,请尝试更新 apt 源:

RUN apt update

4. 禁用 TLS 验证

如果以上方法都无法解决问题,您可以尝试禁用 TLS 验证。请注意,这样做会降低安全性,因此请谨慎使用。

ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update \
  && apt-get install -y --no-install-recommends criu \
  && install -D /usr/sbin/criu /build/criu

5. 检查网络连接

确保 Docker 容器可以访问互联网,并且没有防火墙或其他网络安全配置阻止访问。

6. 使用其他镜像

如果以上方法都无效,您可以尝试使用其他包含 Criu 的 Docker 镜像。

其他建议

  • 使用 --no-install-recommends 选项可以避免安装不必要的依赖项。
  • 确保使用最新的 Docker 版本。

希望这些解决方案能帮助您解决 Dockerfile 中安装 Criu 时遇到的 TLS 连接错误。

Dockerfile 中安装 Criu 并解决 TLS 连接错误

原文地址: https://www.cveoy.top/t/topic/gSZY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录