Given following simple Dockerfile
FROM maven:3.6.3-ibmjava-8-alpine
# Copy maven settings
COPY settings.xml /usr/share/maven/ref/
COPY pom.xml .
# WHY IS settings.xml HERE NOT CONSIDERED?
ENTRYPOINT ["mvn -X"]
# WHY IS settings.xml HERE NOT CONSIDERED?
#OR: RUN mvn clean install deploy
I copy here the settings.xml
as suggested in the maven's docker doc into the image. Now, when I run the container, this will fail with: Could not find artifact com.my.artefactory:my-parent:pom:2.0.2 in central (https://repo.maven.apache.org/maven2)
As we can see here, maven tries to resolve things from the default maven repo - despite the fact that I defined my own maven repo in the settings file.
When I remove ENTRYPOINT ["mvn -X"]
and connect to the container docker run --rm -it mvn-builder sh
, and then manually run mvn -X
in the shell, it actually works! There is also the expected output
[DEBUG] Using mirror my-mirror (https://com.my.artefactory/repository/whatever-repo/) for central (http://central).
What do I miss here?
xml with the dependencies you need and use this in your Dockerfile . /usr/share/maven/ref/settings-docker. xml is a settings file that changes the local repository to /usr/share/maven/ref/repository , but you can use your own settings file as long as it uses /usr/share/maven/ref/repository as local repo.
Docker belongs to "Virtual Machine Platforms & Containers" category of the tech stack, while Apache Maven can be primarily classified under "Java Build Tools". Some of the features offered by Docker are: Integrated developer tools.
The docker Maven plugin allows us to manage all the docker images and pom. xml containers. The pom. xml file of a maven-based project holds all the dependencies, repositories, etc., needed to build and run such a project.
I think the problem is actually the fact that the image I derive from maven:3.6.3-ibmjava-8-alpine
already defines an ENTRYPOINT
.
When I run docker run -it --rm my-image-mvn mvn clean install deploy
it just works fine - good enough for me...
EDIT But I still wonder, why does that not work with ENTRYPOINT (or RUN)?
EDIT 2
Ok, I finally get it, hope it will help somebody else. The maven's image uses an ENTRYPOINT
with a shell script, which will make sure the settings.xml
is placed into the correct directory. This happens only when you start a container instance.
In order to actually make it work for e.g. a RUN
command, you have to do some of the work yourself.
Here is an example:
FROM maven:3.6.3-ibmjava-8-alpine AS maven-builder
# Since we want to execute the mvn command with RUN (and not when the container gets started),
# we have to do here some manual setup which would be made by the maven's entrypoint script
RUN mkdir -p /root/.m2 \
&& mkdir /root/.m2/repository
# Copy maven settings, containing repository configurations
COPY settings.xml /root/.m2
...
RUN mvn clean install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With