I am using the docker-maven-plugin
plugin from fabric8
to setup two containers:
- Postgres
- tomcat8
Both containers can be set up separately fine. I can connect from outside (from the host) to both of them. I am doing this as following:
<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>
I am having troubles to configure that the tomcat8 container is allowed to connect to the Postgres container.
As you can see, I am creating a custom network in each image and the tomcat container depends on the database container.
<network>
<name>network</name>
<alias>database</alias>
</network>
and
<network>
<name>network</name>
<alias>tomcat</alias>
</network>
<dependsOn>
<container>database</container>
</dependsOn>
But I am unable to establish a JDBC connection to localhost:5432
in the tomcat container.
Is this configuration correct? Which IP: PORT
should the tomcat8 use to connect to the database? Ideally, this IP: PORT
should not be fixed, so multiple maven instances can be executed concurrently without interfering (useful for simultaneous builds, such as Jenkins).