Setting up correctly the hostname when using the DMP with 2 images in a network

36 views
Skip to first unread message

Vincent Massol

unread,
Jan 4, 2018, 5:27:29 AM1/4/18
to fabric8
Hi guys,

I have 2 images that I start (mysql and xwiki inside tomcat) and I need to configure the network connectivity between both so that xwiki can talk to the DB.

When using the docker command line I use:

docker run --net=xwiki-nw --name mysql-xwiki -v /my/own/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=xwiki -e MYSQL_USER=xwiki -e MYSQL_PASSWORD=xwiki -e MYSQL_DATABASE=xwiki -d mysql:5.7 --character-set-server=utf8 --collation-server=utf8_bin --explicit-defaults-for-timestamp=1

docker run
--net=xwiki-nw --name xwiki -p 8080:8080 -v /my/own/xwiki:/usr/local/xwiki -e DB_USER=xwiki -e DB_PASSWORD=xwiki -e DB_DATABASE=xwiki -e DB_HOST=mysql-xwiki xwiki:mysql-tomcat




Using DMP I tried the following:

      <plugin>
       
<groupId>io.fabric8</groupId>
       
<artifactId>docker-maven-plugin</artifactId>
       
<version>0.23.0</version>
       
<extensions>true</extensions>
       
<configuration>
         
<imagePullPolicy>IfNotPresent</imagePullPolicy>
         
<autoCreateCustomNetworks>true</autoCreateCustomNetworks>
         
<images>
           
<!-- Execute the MySQL image in a container -->
           
<image>
             
<alias>mysql-xwiki</alias>
             
<name>mysql:5.7</name>
             
<run>
               
<network>
                 
<mode>custom</mode>
                 
<name>xwiki-maven</name>
               
</network>
               
<volumes>
                 
<bind>
                   
<volume>${project.build.directory}/docker/mysql:/var/lib/mysql</volume>
                 
</bind>
               
</volumes>
               
<env>
                 
<MYSQL_ROOT_PASSWORD>xwiki</MYSQL_ROOT_PASSWORD>
                 
<MYSQL_USER>xwiki</MYSQL_USER>
                 
<MYSQL_PASSWORD>xwiki</MYSQL_PASSWORD>
                 
<MYSQL_DATABASE>xwiki</MYSQL_DATABASE>
               
</env>
               
<cmd>
                 
<arg>--character-set-server=utf8</arg>
                 
<arg>--collation-server=utf8_bin</arg>
                 
<arg>--explicit-defaults-for-timestamp=1</arg>
               
</cmd>
               
<log>
                 
<prefix>%n|</prefix>
                 
<date>default</date>
                 
<color>cyan</color>
               
</log>
               
<wait>
                 
<log>.*port: 3306  MySQL Community Server.*</log>
                 
<time>60000</time>
               
</wait>
             
</run>
           
</image>
           
<image>
             
<alias>xwiki</alias>
             
<name>xwiki:latest</name>
             
<run>
               
<dependsOn>
                 
<container>mysql-xwiki</container>
               
</dependsOn>
               
<network>
                 
<mode>custom</mode>
                 
<name>xwiki-maven</name>
               
</network>
               
<volumes>
                 
<bind>
                   
<volume>${project.build.directory}/docker/xwiki:/usr/local/xwiki</volume>
                 
</bind>
               
</volumes>
               
<env>
                 
<DB_USER>xwiki</DB_USER>
                 
<DB_PASSWORD>xwiki</DB_PASSWORD>
                 
<DB_DATABASE>xwiki</DB_DATABASE>
                 
<DB_HOST>mysql-xwiki</DB_HOST>
               
</env>
               
<ports>
                 
<port>18080:8080</port>
               
</ports>
               
<wait>
                 
<http>
                   
<url>http://localhost:18080/xwiki</url>
                 
</http>
                 
<time>60000</time>
               
</wait>
               
<log>
                 
<prefix>%n|</prefix>
                 
<date>default</date>
                 
<color>red</color>
               
</log>
             
</run>
           
</image>
         
</images>
       
</configuration>
     
</plugin>


The important part is <DB_HOST>mysql-xwiki</DB_HOST> which is used in the container to construct the JDBC URL for the DB: jdbc:mysql://mysql-xwiki/xwiki?useSSL=false

This is not working and thus it seems that the alias is not used by DMP to set the hostname/IP.

I then tried defining a <hostname> as in:

<image>
 
<alias>mysql-xwiki</alias>
 
<name>mysql:5.7</name>
 
<run>
   
<hostname>mysql-xwiki</hostname>
...



But it didn't help.

I saw some info on how to customize IPs when using a custom network on https://dmp.fabric8.io/#docker:start but I'd rather not set IPs.

So any idea how both images can address each other?

Thanks
-Vincent


Vincent Massol

unread,
Jan 4, 2018, 5:39:55 AM1/4/18
to fabric8
So in short I'm looking for the DMP way of doing the same as --name with docker run.

Thanks
-Vincent
Reply all
Reply to author
Forward
0 new messages