docker-maven-plugin from fabric8: connection between tomcat and postgres container - maven

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).

I ran into the same issue. I actually ended up with the very same configuration of the docker-maven-plugin as you did following the documentation and also didn't know what would be the URL to get from one container to another.
The missing piece was understanding how Docker networking work. Following this tutorial brought home the message.
In short. To access the database from the tomcat container use database:5432.
When containers are on the same network (e. g. custom bridge network in this case) they can resolve each other using their hostnames - e. g. database. The containers expose ports - in this case database port is randomly-assigned:5432. Now within the Docker network the ports on the machines themselves work - so 5432. From the outside, for instance from the host, it is the randomly-assigned port.

Related

Fabric8 Docker Maven Plugin: docker:tag fails with Cannot invoke "BuildImageConfiguration.cleanupMode()" because "buildConfig" is null

I use FabricIO's Docker Maven Plugin.
I'm trying to create a docker tagged image with Docker Maven Pugin.
The build goal works, but when trying to tag the image, DMP fails:
Execution start of goal io.fabric8:docker-maven-plugin:0.40.2:tag failed: Cannot invoke "io.fabric8.maven.docker.config.BuildImageConfiguration.cleanupMode()" because "buildConfig" is null
docker-maven-plugin version : 0.40.2 (latest 2022-09)
Maven version (mvn -v) :
Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Java version: 18.0.2-ea, vendor: Private Build, runtime: /usr/lib/jvm/java-18-openjdk-amd64
Ubuntu 22.04
I've also opened a bug here since it does not behave according to the documentation:e
https://github.com/fabric8io/docker-maven-plugin/issues/1610
But maybe - Is there something could be doing wrong?
Here is the plugin part of my pom.xml.
Note that I put the docker:tag goal in place of docker:start so that it runs after docker:build if that being missing was the cause.
<plugin>
<!-- The Docker Maven plugin is used to create docker image with the fat jar -->
<groupId>io.fabric8</groupId><artifactId>docker-maven-plugin</artifactId><version>${version.docker-maven-plugin}</version>
<configuration>
<images>
<image>
<alias>mongo</alias>
<name>mongo:5</name>
<run>
<wait><time>6000</time><log>Waiting for connections</log></wait>
<log><prefix>MO</prefix><color>yellow</color></log>
<!-- Assign dynamically mapped ports to maven variable (which can be reused in integration tests) -->
<ports><port>mongo.port:27017</port></ports>
<env>
<MONGO_INITDB_ROOT_USERNAME>root</MONGO_INITDB_ROOT_USERNAME>
<MONGO_INITDB_ROOT_PASSWORD>kotlin4ever</MONGO_INITDB_ROOT_PASSWORD>
</env>
</run>
</image>
<!-- Image holding the artifact of this build -->
<image>
<alias>service</alias><!-- Alias name which can used for linking containers during runtime -->
<name>dacadoo/${project.artifactId}:${project.version}</name>
<build>
<from>openjdk:20</from>
<assembly>
<descriptor>${basedir}/src/main/docker/docker-assembly.xml</descriptor>
<!--
<descriptorRef>artifact-with-dependencies</descriptorRef>
-->
</assembly>
<ports><port>8080</port></ports>
<!--
<cmd>java -jar /maven/tracker-service.jar</cmd>
-->
<entryPoint><exec><arg>java</arg><arg>-jar</arg><arg>/tracker-service.jar</arg></exec></entryPoint>
</build>
<!-- Runtime configuration for starting/stopping/linking containers -->
<run>
<!-- Assign dynamically mapped ports to maven variables (which can be reused in integration tests) -->
<ports><port>service.port:8080</port></ports>
<wait>
<time>10000</time><url>http://${docker.host.address}:${service.port}/health</url>
</wait>
<links><link>mongo:mongo</link></links>
<log><prefix>TS</prefix><color>cyan</color></log>
</run>
</image>
</images>
</configuration>
<!-- Hooking into the lifecycle -->
<executions>
<execution><id>start</id><goals><goal>build</goal><goal>tag</goal></goals><phase>pre-integration-test</phase></execution>
<!--
<execution><id>stop</id><goals><goal>stop</goal></goals><phase>post-integration-test</phase></execution>
-->
</executions>
</plugin>

Publishing and Accessing OSGI Service with JBoss Fuse Fabric

I have an OSGi service that I exposed and deployed on jboss fuse fabric.
now I need to access this service from another bundle deployed on another container in jboss fuse fabric. but the service is not accessible in client container.
jboss fuse V6.3
when I deploy OSGi-service bundle and client bundle in the same container in fuse fabric, it works, but when I deploy the in different containers in does not work and show an error:
Unable to start blueprint container for bundle com.osgi.app.bean-camel-client10/1.0.0 due to unresolved dependencies [(objectClass=org.fusesource.example.service.HelloWorldSvc)]
In client:
POM.xml :
<dependency>
<groupId>com.osgi.app</groupId>
<artifactId>bean-app-service1</artifactId>
<version>1.0</version>
</dependency>
config.xml:
<reference id="helloWorld"
interface="org.fusesource.example.service.HelloWorldSvc"/>
<camelContext xmlns="http://camel.apache.org/schema/blueprint" >
<route>
<from uri="timer:foo?period=5000"/>
<to uri="bean:org.fusesource.example.service.HelloWorldSvc?method=sayHello"/>
<log message="The message contains: ${body}"/>
</route>
in service-provider:
pom.xml:
<groupId>com.osgi.app</groupId>
<artifactId>bean-app-service2</artifactId>
<version>1.0</version>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>${version.maven-bundle-plugin}</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${pom.groupId}.${pom.artifactId}</Bundle-SymbolicName>
<Export-Package>org.fusesource.example.service</Export-Package>
</instructions>
</configuration>
</plugin>
config.xml:
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd
http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint.xsd">
<bean id="hello" class="org.fusesource.example.service.impl.HelloWorldSvcImpl"/>
<service ref="hello" interface="org.fusesource.example.service.HelloWorldSvc"/>
</blueprint>
How can I access the service which is deployed in another container in fuse fabric, through a camel context?
<service ref="hello" interface="org.fusesource.example.service.HelloWorldSvc"/>
means exactly this: call BundleContext.registerService("org.fusesource.example.service.HelloWorldSvc", object, properties).
After registration you have a service registered in local OSGi registry which is scoped by single instance of JVM - that never meant exposing the service to be accessible in different JVM.
If you want a service to be available in different JVM (== in different OSGi registry), you need some kind of remoting - try using CXF endpoint or one of remoting camel components (camel-cxf, camel-rest, ...).

How do I get the Tomcat 7 Embedded container to use another port?

I have Arquillian setup in Gradle to spin up a REST server and run some tests against a REST client. Everything works fine, except for the fact that the server hosting the CI already uses port 8080.
I have added the following settings to my build.gradle file
arquillian {
containers {
tomcat {
version = '7'
config = ['bindHttpPort': 18080]
type = 'embedded'
}
}
}
But it has no effect. How can I change the port used by the embedded tomcat 7 container?
EDIT
There is a workaround, which is to have the following in a file called arquillian.xml. Still, it would be nice to have the option of defining the port in the build.gradle file.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
<container qualifier="tomcat" default="true">
<configuration>
<!-- We need to change the port from the default of 8080 because 8080 is quite commonly not available -->
<property name="bindHttpPort">18080</property>
</configuration>
</container>
</arquillian>

IBM Websphere Liberty Profile:How to map Public IP Address in Websphere

I am trying to map my server public ip addresss in Websphere LP server.xml file but when i tried to access it from outside i am getting a connection error. I tried giving host="localhost" and tried to access from server itself,it is working fine.
Is there anything i need to configure in Websphere LP to access it from outside.
Server.xml file
<server description="new server">
<!-- Enable features -->
<featureManager>
<feature>jsp-2.2</feature>
<feature>localConnector-1.0</feature>
</featureManager>
<httpEndpoint host="*" httpPort="8007" httpsPort="9443" id="defaultHttpEndpoint"/>
<applicationMonitor updateTrigger="mbean"/>
<library id="worklight-6.0.0">
<fileset dir="C:\IBM\Liberty\usr\shared\resources" includes="worklight-jee-library-6.0.0.jar"/>
</library>
<library id="apps-common">
<fileset dir="C:\IBM\Liberty\usr\shared\resources" includes="org.hsqldb.hsqldb_2.2.5.jar"/>
</library>
<application context-root="/DemoApp" id="DemoApplication" location="DemoApplication.war" name="DemoApplication" type="war">
<classloader commonLibraryRef="worklight-6.0.0,apps-common"/>
</application>
</server>
Any help is appreciated.
As per the InfoCenter document for the httpEndpoint configuration element, here: http://pic.dhe.ibm.com/infocenter/wasinfo/v8r5/topic/com.ibm.websphere.wlp.doc/autodita/rwlp_metatype_4ic.html?resultof=%22%68%74%74%70%65%6e%64%70%6f%69%6e%74%22%20#mtFile121
A hostname of * will bind to all available network interfaces - you do not need to do anything extra on the Liberty side, which I believe answers your question.
Setting the hostname to 'localhost' will mean the http endpoint is only accessible from your machine.
Using the configuration as supplied (hostName of *), this should work remotely - so it is likely a firewall issue.
You can check the /servers/yourServer/logs/messages.log file to verify which interfaces your endpoint is binding to - look for a message of the form
WWKO0219I: TCP Channel defaultHttpEndpoint has been started and is now listening for requests on host localhost (IPv4: 127.0.0.1) port 9080.

Using through a proxy server

I am trying to use the solrnet library to connect to my solr instance through a proxy server and I am not having any luck. Does anyone know if this is possible and if so how?
EDIT: I tried to do this using the configuration option as specified by Mauricio Scheffer but ran into an error on try to build the project. After resolving the related issue regarding the project being stored on NAS, I have implemented Mauricio's IHttpWebRequestFactory solution and it works perfectly
Cheers,
Ed
You can either:
set <defaultProxy> in your config (which defines a global proxy), or
implement HttpWebAdapters.IHttpWebRequestFactory (included in SolrNet) and make your implementation return a IHttpWebRequest with the Proxy property set to whatever your need, then register your IHttpWebRequestFactory implementation in your IoC container.
This is the configuration when it built:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
When I added this:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.net>
<defaultProxy>
<proxy proxyaddress="MY-PROXY"/>
</defaultProxy>
</system.net>
</configuration>
It failed to build.
I have found that it's due to the project being stored on a network drive. Moving the project to the local machine fixed it, although I have since run caspol to allow me to run it from the network area.
Ed

Resources