java - 无法在 Docker 中访问 Maven 依赖项
问题描述
我试图从 docker 文件运行 java 应用程序。该应用程序通过 Maven 运行。
当我尝试从下图中启动容器时,出现以下错误。
[ERROR] error reading /root/.m2/repository/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.jar; zip END header not found
[ERROR] error reading /root/.m2/repository/junit/junit/4.12/junit-4.12.jar; zip END header not found
[ERROR] error reading /root/.m2/repository/info/cukes/cucumber-java/1.2.5/cucumber-java-1.2.5.jar; zip END header not found
[ERROR] error reading /root/.m2/repository/info/cukes/cucumber-junit/1.2.5/cucumber-junit-1.2.5.jar; zip END header not found
[ERROR] error reading /root/.m2/repository/org/json/json/20180813/json-20180813.jar; zip END header not found
[ERROR] /temproj/src/test/java/pages/terms/Terms_Chrome.java:[1,1] cannot access pages.terms
[ERROR] zip END header not found
[ERROR] /temproj/src/test/java/config/RunCukesTest.java:[1,1] cannot access config
[ERROR] zip END header not found
[ERROR] /temproj/src/test/java/utils/SetProperty.java:[1,1] cannot access utils
[ERROR] zip END header not found
[ERROR] /temproj/src/test/java/pages/sign_in/SignIn.java:[1,1] cannot access pages.sign_in
[ERROR] zip END header not found
我的 Docker 文件
FROM maven
COPY . /temproj
RUN mkdir -p /root/.m2/repository/ \
mvn install
WORKDIR /temproj
ENTRYPOINT ["mvn", "verify"]
Pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ecs.googleuat</groupId>
<artifactId>googleuat</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<sele.lib.version>3.141.59</sele.lib.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.github.temyers</groupId>
<artifactId>cucumber-jvm-parallel-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<id>generateRunners</id>
<phase>generate-test-sources</phase>
<goals>
<goal>generateRunners</goal>
</goals>
<configuration>
<glue>
<package>
steps
</package>
</glue>
<outputDirectory>target/generated-test-sources/cucumber</outputDirectory>
<featuresDirectory>src/test/resources/features</featuresDirectory>
<cucumberOutputDir>target/cucumber-parallel</cucumberOutputDir>
<namingPattern>Parallel{c}IT</namingPattern>
<format>json,html</format>
<parallelScheme>FEATURE</parallelScheme>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.21.0</version>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>integration-test</goal>
</goals>
<configuration>
<forkCount>10</forkCount>
<reuseForks>true</reuseForks>
<includes>
<include>**/*IT.class</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.3.5</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- vinsdocker is org name. -->
<!-- containertest is the name of the image / application -->
<repository>chrisdocker/selcontainertest</repository>
<!-- version of your image: could be sprint11 or release5 etc -->
<tag>googletest</tag>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<repositories>
<repository>
<id>sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>repo.jenkins-ci.org</id>
<url>http://repo.jenkins-ci.org/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>${sele.lib.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server</artifactId>
<version>${sele.lib.version}</version>
</dependency>
<!--<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-server-standalone</artifactId>
<version>${sele.lib.version}</version>
</dependency>-->
</dependencies>
</project>
感谢解决这个问题的一些帮助,我认为这可能与容器内的用户权限有关。
解决方案
FROM maven
COPY . /app/
WORKDIR /app
RUN mvn install
ENTRYPOINT ["mvn", "verify"]
推荐阅读
- r - 将坐标 (x,y) 转换为角度并在 r 中创建玫瑰图
- regex - 需要 Ansible 正则表达式帮助:无法获取输出并分配给 set_fact 变量
- python-3.x - Matplotlib 按字符串列表排列数据以按顺序获取标签(在 ax 上而不是 plt 上)
- html - 如何在 chrome 媒体控制菜单和 Windows 媒体控制对话框中设置 HTML 音频或视频缩略图和标题
- javascript - 如何将基于索引的数据移动到不同的表中
- java - 返回类型为 void 的 Lambda 表达式可以使用 wrapper 编译,但不能使用原始编译
- python - Keras 预测准确性与拟合结果不匹配
- c# - 一个模型、多个视图模型和使用 WPF 的可更新视图?
- c# - 我无法在 C# 中收到肥皂消息
- php - 休息API || 代码点火器 || 未定义授权