Unknown host maven2: Name or service not known when building maven in docker
I’m trying to launch mvn clean install
inside a docker and I keep getting error:
`Downloading from foo: http://maven2:8081/repository/foo/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.239 s
[INFO] Finished at: 2020-10-06T13:27:37Z
[INFO] ------------------------------------------------------------------------
[ERROR] Plugin org.apache.maven.plugins:maven-clean-plugin:2.5 or one of its dependencies could not be resolved: Failed to read artifact descriptor for org.apache.maven.plugins:maven-clean-plugin:jar:2.5: Could not transfer artifact org.apache.maven.plugins:maven-clean-plugin:pom:2.5 from/to foo (http://maven2:8081/repository/foo/): Transfer failed for http://maven2:8081/repository/foo/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom: Unknown host maven2: Name or service not known -> [Help 1]`
I’m using companies local maven. The settings file is:
<?xml version="1.0" encoding="UTF-8"?>
<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
http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>foo</id>
<mirrorOf>*</mirrorOf>
<url>http://maven2:8081/repository/foo/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>foo</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<repositories>
<repository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://central</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>foo</activeProfile>
</activeProfiles>
</settings>
If I delete settings.xml or setup redirects to central
<mirror>
<id>https-mirror</id>
<name>Https Mirror Repository</name>
<url>https://repo1.maven.org/maven2</url>
<mirrorOf>central</mirrorOf>
</mirror>
the program builds without a problem, but script that generates the product fails the second it needs to download something that is stored on our nexus.
All the requests to maven2
seem to be valid. If I use browser
or wget
to access the http://maven2:8081/repository/foo/org/apache/maven/plugins/maven-clean-plugin/2.5/maven-clean-plugin-2.5.pom
I get it without any problem.
maven version:
[email protected]:/mnt# mvn -version
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /opt/apache-maven
Java version: 1.8.0_265, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.19.128-microsoft-standard", arch: "amd64", family: "unix"
Other people also use the same docker image and settings file and it seems to be working for them.
I also tried removeing /repository from /.m2/
relaunching the image
and like >50 different solutions on stack overflow in a course of few days and nothing seems to work
Source: Docker Questions