I am working to migrate our Maven build process into Docker for our existing Java projects. I am an experienced Java developer using Maven, but still learning Docker.
Our primary problem is that by default artifacts are not cached so we download half the Internet every five minutes, combined with we also have things on a local elderly Nexus server. As this is for automated integration testing we do not want to build the artifacts outside of docker.
After careful consideration I found that a good solution could be to have a Maven mirroring proxy running for each developer where the local configuration can be kept and the Docker instances then just refer to that. Manually running a Nexus3 container with
docker run -p 8081:8081 --name nexus sonatype/nexus3
(plus some manual configuration to proxy our internal repository too) has worked very well so far, but is not controlled by docker-compose.
Unfortunately I cannot see a way for the guests to access the host (where port 8081 is available) other than hardcoding the external IP-number of the machine, and I cannot see a way to make docker-compose responsible for ensuring that the nexus container is running when my docker builds needs it.
I am currently using this as the settings.xml file inside docker:
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
https://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>local-nexus</id>
<name>Local Nexus</name>
<!-- Host external IP number -->
<url>http://1.2.3.4:8081/repository/sbforge_central/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<localRepository>/usr/share/maven/ref/repository</localRepository>
</settings>
How should I approach this? I see two scenarios.
How can I get a reliable name for the host? Linux is required, other platforms will be nice.
How can I make docker-compose control this container so it is up when running
docker-compose build
so docker can ensure that the hostname of the nexus container resolves? It is not needed when bringing the finished containers up.
Or is there a smarter way?