我正在使用包含所有 maven 配置、密钥、maven 命令的 sh 文件。当我运行容器时,它每次都会一次又一次地下载依赖项,它无法缓存依赖项。
这是我的 Dockerfile 的样子:
#MVN as build tool
FROM docker.hub.com/maven:3.5.3-jdk-8
#Settings.xml for downloading dependencies from nexus repository
ARG MVN_SETTINGS=settings.xml
#Maven project pom
ARG MVN_POM=pom.xml
#Defining the current working repository
WORKDIR /usr/src/app
#Coping the settings.xml into working directory
COPY ${MVN_SETTINGS} settings.xml
#Coping the pom.xml into working directory
COPY ${MVN_POM} pom.xml
#Download the package and make it cached in docker image
RUN mvn -B -f ./pom.xml -s settings.xml dependency:resolve-plugins dependency:resolve
#Coping the source code into working repository
COPY src .
COPY Test.sh .
#Execute permission
RUN chmod a+x Test.sh
#Entry point for docker container
CMD ./Test.sh
这是 Test.sh 文件
#!bin/bash
mvn test -DtestSuite=src/test/resources/suites/Suite.xml
当我创建 docker 映像并运行容器时,它会一次又一次地下载依赖项,每次运行它。