来自fabric8的docker-maven-plugin:tomcat和postgres容器之间的连接

我使用fabric8 docker-maven-plugin插件来设置两个容器:

  • Postgres的
  • tomcat8

两个容器都可以单独设置好。 我可以从外部(从主机)连接到他们两个。 我正在做这个如下:

 <plugin> <groupId>io.fabric8</groupId> <artifactId>docker-maven-plugin</artifactId> <version>0.22.1</version> <configuration> <autoCreateCustomNetworks>true</autoCreateCustomNetworks> <images> <image> <alias>database</alias> <name>postgres:9</name> <run> <network> <name>network</name> <alias>database</alias> </network> <ports> <port>db-port:5432</port> </ports> <wait> <log>ready to accept connections</log> </wait> </run> </image> <image> <alias>container</alias> <name>inovatrend/tomcat8-java8</name> <run> <network> <name>network</name> <alias>tomcat</alias> </network> <dependsOn> <container>database</container> </dependsOn> <ports> <port>tomcat-port:8080</port> </ports> <wait> <http> <url>http://localhost:${tomcat-port}</url> </http> </wait> </run> </image> </images> </configuration> </plugin> 

我有麻烦configurationtomcat8容器被允许连接到postgres容器。

正如你所看到的,我正在每个镜像中创build一个自定义的networking,tomcat容器依赖于数据库容器。

 <network> <name>network</name> <alias>database</alias> </network> 

 <network> <name>network</name> <alias>tomcat</alias> </network> <dependsOn> <container>database</container> </dependsOn> 

但是我无法build立JDBC连接到tomcat容器中的localhost:5432

这个configuration是否正确? Tomcat8使用哪个IP:PORT来连接数据库? 理想情况下,这个IP:PORT不应该是固定的,所以可以同时执行多个maven实例而不会干扰(对于同时构build,比如Jenkins很有用)。