Maven and Dockerfile - download dependencies on container creation

Viewed 276

I want to run tests on Java + TestNG in Docker container with Maven. I am trying to make Maven download all dependencies while I create an image via Dockerfile. So it shouldn't download it on a container run.

I have two variants of Dockerfile which are not working properly.

FROM maven:3.6.3-ibmjava-8

WORKDIR /tests

COPY . .

RUN mvn dependency:resolve -q

CMD mvn -Dtest=SimpleTest test

Here Maven downloads dependencies in RUN while the image is creating and downloads it again when the container is running. о_О

FROM maven:3.6.3-ibmjava-8

WORKDIR /tests

COPY . .

RUN mvn install -q

CMD mvn -Dtest=SimpleTest test

Here Maven is trying not only to download dependencies but launch tests on RUN stage.

How can I only download Maven dependencies once while I create the image (on RUN stage) and launch tests without downloading dependencies again on the container run?

Thank you in advance.

1 Answers

Try

FROM maven:3.6.3-ibmjava-8

WORKDIR /tests

COPY . .

RUN mvn dependency:go-offline

CMD mvn --offline -Dtest=SimpleTest test

Related