Docker - maven connect to specific repository in runtime
Solution 1
Regarding the feedback, we've came up with the following solution.
The settings.xml was added to the project build folder and the DockerFile looks like this:
...
RUN apt-get update
RUN apt-get install -y maven
ADD /path/to/settings.xml /root/.m2/settings.xml
...
and in the run script file we added the repository (this will write on /etc/hosts):
...
docker run --add-host=myrepo.mycompany.com:<ip> ...
...
and now the application can resolve runtime dependencies!
Solution 2
You can do this by creating a volume mapping
docker run ... -v /path/on/host/settings.xml:/home/me/.m2/settings.xml ....
see also the following example where the repository is run within a container and accessed via a link:
bsferreira
Updated on June 16, 2022Comments
-
bsferreira almost 2 years
I've an image which needs to connect to a repository in runtime, but it seams that Docker container is not able to read ~/.m2/settings.xml file located in host machine.
Is there any way to let docker now where maven configuration file is located? Or actually import the maven configuration file to the container?
-
bsferreira over 9 yearsI'm not sure if I explained myself well. When I said host machine, I mean the machine where docker seats on. So, I've tried
-v /home/user/.m2/settings.xml
, but I get the same response (not finding the jar in the repo). Do you have any other clue? do I need to install maven in the container? -
Mark O'Connor over 9 years@RodreNathan Now I'm confused... If you're trying to run Maven, then yes it must be installed in the container.
-
bsferreira over 9 yearsYes, I've installed it and made some configurations, which I'll post for the record and help someone with the same problem.
-
Mark O'Connor over 9 yearsCheck out a similar answer. Uses the official Maven image (no need to build one). Additionally instead of an add-host, uses a Nexus image running in a linked container. See: stackoverflow.com/questions/27767264/…
-
Carlos about 8 yearsYou can also declare a VOLUME in order to be able to set or change the settings file at "docker run" time.