在Debian中正确安装curl以及–no-install-recommends选项

38次阅读
没有评论

问题描述

正在构建一个基于debian:buster-slim镜像的Docker映像,并在此映像中安装cUrl。根据Hadolint的建议,他使用apt-get命令安装所有软件包,并使用选项--no-install-recommends来避免安装不必要的软件包。然而,以这种方式安装的cUrl无法通过HTTPS获取任何文件,因为它无法找到”本地发行证书”,如下面从Docker输出中摘录的内容所示。用户想知道需要安装哪个额外的软件包来解决这个问题。

Step 15/19 : RUN set -ex; curl --output distribution.zip $FULL_URL
---> Running in 9aa176a788d7+ curl --output distribution.zip https://www.host.domain/file.zip
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (60) SSL certificate problem: unable to get local issuer certificate
More details here: https://curl.haxx.se/docs/sslcerts.html
curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.

以下是用户当前使用的Dockerfile版本:

FROM debian:buster-slim
RUN set -ex; apt-get -y update
RUN set -ex; \
    apt-get -y install --no-install-recommends \
        curl=7.64.0-4+deb10u1 \
        unzip=6.0-23+deb10u1 \
        coreutils=8.30-3 \
        lsb-release build-essential ssh-client apt-transport-https \
        python gnupg
RUN set -ex; curl --output distribution.zip https://www.host.domain/file.zip

解决方案

请注意以下操作可能涉及版本差异或配置修改,务必谨慎操作。
为了解决cUrl在HTTPS获取文件时无法找到本地颁发证书的问题,您需要安装ca-certificates软件包。这将为cUrl提供所需的本地颁发证书,以便在进行安全连接时进行验证。

以下是您的Dockerfile中需要做的更改:

FROM debian:buster-slim
RUN set -ex; apt-get -y update
RUN set -ex; \
    apt-get -y install --no-install-recommends \
        ca-certificates \  # 添加此行以安装ca-certificates
        curl=7.64.0-4+deb10u1 \
        unzip=6.0-23+deb10u1 \
        coreutils=8.30-3 \
        lsb-release build-essential ssh-client apt-transport-https \
        python gnupg
RUN set -ex; curl --output distribution.zip https://www.host.domain/file.zip

通过将ca-certificates添加到安装列表中,您将为cUrl提供所需的本地颁发证书,使其能够正常验证HTTPS连接,并成功获取文件。

请注意,本文提供的解决方案是基于已提供的问题和回答数据进行的。在进行更改之前,建议您备份相关的配置文件,以防出现意外问题。

这些步骤应该能够帮助您在Debian中正确安装cUrl,并使用--no-install-recommends选项避免安装不必要的软件包。如果您在实施过程中遇到任何问题,请随时寻求进一步的帮助。

正文完