我正在尝试克隆一个 git 项目并执行以下操作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 [email protected]: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 中声明它,如下所示(此外,您可以使用 run 的 exec 形式):
FROM maven
ARG MAVEN_OPTS
RUN ["mvn", "package"]
那么你的 docker 构建将如下所示:
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" .
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)