使用CURL的Apache Maven下载超时


curl -O "https://www.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz"

这是我从终端下载maven的命令,但它要么超时,要么curl: (7) Failed to connect to www.apache.org port 443: Operation timed out.

如果我使用浏览器下载,没有问题。

我的假设是ssl连接或证书问题。知道我该如何解决卷曲问题吗。

请注意,我在Dockerfile中使用它来创建docker映像,这里是:

FROM ******/mule-42x:v2.2.1
ENV MAVEN_VERSION 3.6.3
RUN mkdir -p /opt/maven 
&& cd /opt/maven 
&& curl -O "https://www.apache.org/dist/maven/maven-3/${MAVEN_VERSION}/binaries/apache-maven-${MAVEN_VERSION}-bin.tar.gz" 
&& tar xzvf "apache-maven-$MAVEN_VERSION-bin.tar.gz" 
&& rm "apache-maven-$MAVEN_VERSION-bin.tar.gz"
ENV MAVEN_HOME "/opt/maven/apache-maven-$MAVEN_VERSION"
ENV PATH=$MAVEN_HOME/bin:$PATH

我尝试运行问题中提供的命令,但遇到了以下错误:

curl -O "https://www.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz"
  1. curl尝试验证SSL证书,但失败,并显示以下消息:
curl: (60) server certificate verification failed. CAfile: /etc/ssl/certs/ca-certificates.crt CRLfile: none
More details here: http://curl.haxx.se/docs/sslcerts.html
curl performs SSL certificate verification by default, using a "bundle"
of Certificate Authority (CA) public keys (CA certs). If the default
bundle file isn't adequate, you can specify an alternate file
using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented in
the bundle, the certificate verification probably failed due to a
problem with the certificate (it might be expired, or the name might
not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate, use
the -k (or --insecure) option.

因此,正如消息所示,我添加了-k标志。

  1. 现在可以工作了,但是http调用返回一个HTML页面,其中302(重定向(到https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

所以对我有效的命令是:

curl -O -k https://downloads.apache.org/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz

一个重要的附带说明:

我假设您已经正确配置了网络,并且如果您在组织中的代理后面运行,它具有所有正确的代理定义,否则您应该首先定义代理。

总而言之,我建议您首先在运行docker build的机器上的docker之外"手动"运行此命令(我的意思是从命令行而不是作为构建的一部分(,并且只有在确保它有效时才在docker文件中运行它。

最新更新