Maven,Docker获取主机系统的实际IP地址

使用Maven和docker-maven-plugin,我configuration了Apache Kafka + ZooKeeper容器:

<image> <name>wurstmeister/zookeeper:${zookeeper.version}</name> <alias>zookeeper</alias> <run> <ports> <port>${zookeeper.port}:2181</port> </ports> </run> </image> <image> <name>wurstmeister/kafka:${kafka.version}</name> <alias>kafka</alias> <run> <ports> <port>9093:9092</port> </ports> <links> <link>zookeeper:zookeeper</link> </links> <env> <KAFKA_ADVERTISED_HOST_NAME>192.168.1.202</KAFKA_ADVERTISED_HOST_NAME> <KAFKA_ADVERTISED_PORT>9093</KAFKA_ADVERTISED_PORT> <KAFKA_ZOOKEEPER_CONNECT>zookeeper:${zookeeper.port}</KAFKA_ZOOKEEPER_CONNECT> </env> </run> </image> 

正如你所看到的,为了得到它的工作,我必须提供我的主机系统的实际IP地址:

 <KAFKA_ADVERTISED_HOST_NAME>192.168.1.202</KAFKA_ADVERTISED_HOST_NAME> 

在Maven或者docker-maven-plugin中有没有办法自动获得这个IP地址,而不需要硬编码呢?

更新

我find了允许我检索主机IP地址的插件:

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <id>get-local-ip</id> <goals> <goal>local-ip</goal> </goals> <configuration> <localIpProperty>local.ip</localIpProperty> </configuration> </execution> </executions> </plugin> 

但为了使用它,我需要在Maven命令的其余部分之前执行build-helper:local-ip目标:

 mvn build-helper:local-ip docker:start 

如何绑定这个插件的某个阶段/目标,以便在一些早期的初始化阶段自动调用它,而不需要每次都手动调用build-helper:local-ip

从build-helper-maven-plugin的文档 :

默认绑定到生命周期阶段:process-test-classes

你可以改变它绑定到你想要的任何阶段,例如

  <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>build-helper-maven-plugin</artifactId> <executions> <execution> <goals> <goal>local-ip</goal> </goals> <phase>initialize</phase> </execution> </executions> </plugin>