Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for --add-host host.docker.internal:host-gateway #1527

Closed
adamretter opened this issue Feb 20, 2022 · 1 comment · Fixed by #1687
Closed

Support for --add-host host.docker.internal:host-gateway #1527

adamretter opened this issue Feb 20, 2022 · 1 comment · Fixed by #1687

Comments

@adamretter
Copy link

adamretter commented Feb 20, 2022

Since Docker 20.10.0 it is now possible to specify --add-host host.docker.internal:host-gateway which will add an entry to the /etc/hosts file of the container like:

172.17.0.1      host.docker.internal

Which makes it easier for the Container to communicate with the Host.

I tried to use the extraHosts option of the docker-maven-plugin like this:

 <extraHosts>
    <host>host.docker.internal:host-gateway</host>
</extraHosts>

Unfortunately that yields the following error:

Caused by: java.lang.IllegalArgumentException: unable to resolve ip address for host-gateway
    at io.fabric8.maven.docker.access.ContainerHostConfig.extraHosts (ContainerHostConfig.java:97)
    at io.fabric8.maven.docker.service.RunService.createContainerHostConfig (RunService.java:420)
    at io.fabric8.maven.docker.service.RunService.createContainerConfig (RunService.java:379)
    at io.fabric8.maven.docker.service.RunService.createContainer (RunService.java:152)
    at io.fabric8.maven.docker.service.RunService.createAndStartContainer (RunService.java:190)
    at io.fabric8.maven.docker.service.helper.StartContainerExecutor.startContainer (StartContainerExecutor.java:47)
    at io.fabric8.maven.docker.StartMojo.lambda$startImage$0 (StartMojo.java:298)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly (TrustedListenableFutureTask.java:125)
    at com.google.common.util.concurrent.InterruptibleTask.run (InterruptibleTask.java:69)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run (TrustedListenableFutureTask.java:78)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute (MoreExecutors.java:321)
    at java.util.concurrent.ExecutorCompletionService.submit (ExecutorCompletionService.java:181)
    at io.fabric8.maven.docker.StartMojo.startImage (StartMojo.java:296)
    at io.fabric8.maven.docker.StartMojo.executeInternal (StartMojo.java:165)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:280)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    ...
Caused by: java.net.UnknownHostException: host-gateway: Name or service not known
    at java.net.Inet6AddressImpl.lookupAllHostAddr (Native Method)
    at java.net.InetAddress$2.lookupAllHostAddr (InetAddress.java:929)
    at java.net.InetAddress.getAddressesFromNameService (InetAddress.java:1324)
    at java.net.InetAddress.getAllByName0 (InetAddress.java:1277)
    at java.net.InetAddress.getAllByName (InetAddress.java:1193)
    at java.net.InetAddress.getAllByName (InetAddress.java:1127)
    at java.net.InetAddress.getByName (InetAddress.java:1077)
    at io.fabric8.maven.docker.access.ContainerHostConfig.extraHosts (ContainerHostConfig.java:95)
    at io.fabric8.maven.docker.service.RunService.createContainerHostConfig (RunService.java:420)
    at io.fabric8.maven.docker.service.RunService.createContainerConfig (RunService.java:379)
    at io.fabric8.maven.docker.service.RunService.createContainer (RunService.java:152)
    at io.fabric8.maven.docker.service.RunService.createAndStartContainer (RunService.java:190)
    at io.fabric8.maven.docker.service.helper.StartContainerExecutor.startContainer (StartContainerExecutor.java:47)
    at io.fabric8.maven.docker.StartMojo.lambda$startImage$0 (StartMojo.java:298)
    at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly (TrustedListenableFutureTask.java:125)
    at com.google.common.util.concurrent.InterruptibleTask.run (InterruptibleTask.java:69)
    at com.google.common.util.concurrent.TrustedListenableFutureTask.run (TrustedListenableFutureTask.java:78)
    at java.util.concurrent.Executors$RunnableAdapter.call (Executors.java:511)
    at java.util.concurrent.FutureTask.run (FutureTask.java:266)
    at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute (MoreExecutors.java:321)
    at java.util.concurrent.ExecutorCompletionService.submit (ExecutorCompletionService.java:181)
    at io.fabric8.maven.docker.StartMojo.startImage (StartMojo.java:296)
    at io.fabric8.maven.docker.StartMojo.executeInternal (StartMojo.java:165)
    at io.fabric8.maven.docker.AbstractDockerMojo.execute (AbstractDockerMojo.java:280)
    at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
    ...

Info

  • docker-maven-plugin version : 0.39.0
  • Maven version (mvn -v) :
Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /home/aretter/.sdkman/candidates/maven/current
Java version: 1.8.0_312, vendor: BellSoft, runtime: /home/aretter/.sdkman/candidates/java/8.0.312.fx-librca/jre
Default locale: en_GB, platform encoding: UTF-8
OS name: "linux", version: "5.13.0-28-generic", arch: "amd64", family: "unix"
  • Docker version : 20.10.12, build e91ed57
@adamretter adamretter changed the title Support for --add-host host.docker.internal:host-gateway Support for --add-host host.docker.internal:host-gateway Feb 20, 2022
azaaiman added a commit to azaaiman/docker-maven-plugin that referenced this issue Jun 18, 2023
…xtraHosts entry

Signed-off-by: Auke Zaaiman <a.zaaiman@developersdock.com>
rohanKanojia pushed a commit to azaaiman/docker-maven-plugin that referenced this issue Jul 28, 2023
…xtraHosts entry

Signed-off-by: Auke Zaaiman <a.zaaiman@developersdock.com>
rohanKanojia pushed a commit to azaaiman/docker-maven-plugin that referenced this issue Jul 28, 2023
…xtraHosts entry

Signed-off-by: Auke Zaaiman <a.zaaiman@developersdock.com>
rohanKanojia pushed a commit that referenced this issue Jul 28, 2023
… entry

Signed-off-by: Auke Zaaiman <a.zaaiman@developersdock.com>
@adamretter
Copy link
Author

Thank you :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant