Do not download all Maven dependencies on the Docker build

I am trying to create a Docker file to create a Maven project.

I wonder how to fix the Docker file and what command to execute.

I would like to know how to run the assembly so that it does NOT load all Maven dependencies every time it is built, when the source code located in the src / directory has NOT changed.

Here is my Dockerfile:

FROM maven:3.3.9-jdk-8

RUN mkdir -p /usr/src/app

WORKDIR /usr/src/app

RUN cd /usr/src/app

ADD pom.xml /usr/src/app

RUN mvn dependency:resolve

ADD src /usr/src/app

RUN mvn package

ENTRYPOINT ["mvn"]
CMD ["package"]

Should I run a team docker run --rm -it toolboxor team docker build -t toolbox .?

Both of these commands work fine, except that they both download all Maven dependencies, even if the source code has not been affected.

+4
source share
1 answer

. , docker run, , . , , . , . Dockerfile Maven, /root/.m2. , - -v. Docker ,

`docker run -v <directory-in-your-host>:/root/.m2 <other-options-and-commands>

, docker run, Maven .

, , , - . Docker java docker-maven-plugin, spotify. .

+3

All Articles