release-engineering/buildmetadata-maven-plugin

Building inside container: Name or service not known

Closed this issue · 3 comments

I'm building within a docker container and I'm getting the error Name or service not known:

[ERROR] Failed to execute goal com.redhat.rcm.maven.plugin:buildmetadata-maven-plugin:1.7.0:provide-buildmetadata (default) on project consultant-services: Cannot determine host information. 12966f6e4eac: 12966f6e4eac: Name or service not known -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.redhat.rcm.maven.plugin:buildmetadata-maven-plugin:1.7.0:provide-buildmetadata (default) on project consultant-services: Cannot determine host information.
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
	at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
	at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
	at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307)
	at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193)
	at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106)
	at org.apache.maven.cli.MavenCli.execute(MavenCli.java:863)
	at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:288)
	at org.apache.maven.cli.MavenCli.main(MavenCli.java:199)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
	at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
	at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
	at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoExecutionException: Cannot determine host information.
	at com.redhat.rcm.maven.plugin.buildmetadata.data.HostMetaDataProvider.provideBuildMetaData(HostMetaDataProvider.java:70)
	at com.redhat.rcm.maven.plugin.buildmetadata.BuildMetaDataMojo.provideHostMetaData(BuildMetaDataMojo.java:672)
	at com.redhat.rcm.maven.plugin.buildmetadata.BuildMetaDataMojo.createBuildProperties(BuildMetaDataMojo.java:580)
	at com.redhat.rcm.maven.plugin.buildmetadata.BuildMetaDataMojo.execute(BuildMetaDataMojo.java:553)
	at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
	at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:207)
	... 20 more
Caused by: java.net.UnknownHostException: 12966f6e4eac: 12966f6e4eac: Name or service not known
	at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
	at com.redhat.rcm.maven.plugin.buildmetadata.data.HostMetaDataProvider.provideBuildMetaData(HostMetaDataProvider.java:64)
	... 25 more
Caused by: java.net.UnknownHostException: 12966f6e4eac: Name or service not known
	at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
	... 26 more
[ERROR]
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

12966f6e4eac is pointing to the docker host in this scenario. How can I get this to proceed?

This is most likely due to your docker configuration. I'm guessing your container's /etc/hosts doesn't contain an entry for whatever's being reported as the hostname in the JVM...that looks like a hash to me, and probably was generated by docker when starting the container.

You might have some luck running docker exec -ti <container-id> /bin/bash and looking around at the contents of /etc/hosts, and the output of hostname inside the container. It won't solve the problem, but might give some clues as to what's misconfigured.

@jdcasey: this is what /etc/hosts looks like:

127.0.0.1	localhost
::1	localhost ip6-localhost ip6-loopback
fe00::0	ip6-localnet
ff00::0	ip6-mcastprefix
ff02::1	ip6-allnodes
ff02::2	ip6-allrouters
172.17.0.2	12966f6e4eac

hostname: command not found (it's an alpine container, super minimal, so I think hostname isn't installed).

I fixed my issue by creating /etc/nsswitch.conf:

cat /etc/nsswitch.conf

hosts: files dns