gpt4 book ai didi

Maven 无法连接到 docker 内的网络

转载 作者:行者123 更新时间:2023-12-02 18:44:41 25 4
gpt4 key购买 nike

我正在尝试克隆一个 git 项目并在 docker 中执行 mvn package。但是 maven 无法连接到网络来下载依赖项。这是 Dockerfile:

FROM java:8
FROM maven
ADD id_rsa /root/.ssh/id_rsa
ADD known_hosts /root/.ssh/known_hosts
RUN git clone git@myhub.mygithub.com:project/myapp.git
WORKDIR myapp
RUN mvn package

这是maven构建命令:

sudo docker build --build-arg http_proxy=http://proxy.in.my.com:80  
--build-arg https_proxy=http://proxy.in.my.com:80
--build-arg ftp_proxy=http://proxy.in.my.com:80
--build-arg no_proxy=localhost,127.0.0.1,.us.my.com,.my.com
-t myapp .

我在 mvn package 期间遇到以下错误:

Downloading: https://repo.maven.apache.org/maven2/org/jacoco/jacoco-maven-plugin/0.7.6.201602180812/jacoco-maven-plugin-0.7.6.201602180812.pom  

[ERROR] Plugin org.jacoco:jacoco-maven-plugin:0.7.6.201602180812 or one of its dependencies could not be resolved:
Failed to read artifact descriptor for org.jacoco:jacoco-maven-plugin:jar:0.7.6.201602180812: Could not transfer artifact org.jacoco:jacoco-maven-plugin:pom:0.7.6.201602180812 from/to central (https://repo.maven.apache.org/maven2): Network is unreachable (connect failed) -> [Help 1]

最佳答案

实际上,您可以将 MAVEN_OPTS 作为构建参数传递,但您首先必须像这样在 Dockerfile 中声明它(也可以使用 exec 形式的运行):

FROM maven
ARG MAVEN_OPTS
RUN ["mvn", "package"]

然后你的 docker build 看起来像这样:

docker build -t my_image --build-arg http_proxy=http://proxy:3128 --build-arg https_proxy=http://proxy:3128 --build-arg MAVEN_OPTS="-Dhttp.proxyHost=proxy -Dhttp.proxyPort=3128 -Dhttps.proxyHost=proxy -Dhttps.proxyPort=3128" .

关于Maven 无法连接到 docker 内的网络,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45892111/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com