2 Replies Latest reply on Feb 2, 2016 2:05 PM by damaru

    Configuring a datasource in Wildfly using environment variables for Docker

    damaru

      Hi,

       

      I'm preparing to get our Wildfly applications running on Docker. I'm stuck on one thing though.

       

      I've got a mysql datasource configued in a customized version of standalone.xml. I'm trying to figure out how to reconfigure it to take the parameters:

       

      database server

      database name

      database username

      database password

       

      from environment variables. It would be lovely If I could write, in standalone.xml, something like:

       

      <connection-url>${env:DB_CONNECTION_URL}</connection-url>

       

      Now, a certain Marek Goldman has published some solutions to this here:

       

      https://goldmann.pl/blog/2014/07/23/customizing-the-configuration-of-the-wildfly-docker-image/

       

      The one that seems best is configuring the datasource using a cli script after wildfly is running, but that seems like a kludge.

       

      There must be a better way! Maybe there's some magic syntax in the wildfly config files that I'm not aware of, that lets you reference environment variables?

       

      thanks

      Michael Davis

      Ottawa

        • 1. Re: Configuring a datasource in Wildfly using environment variables for Docker
          jaysensharma

          WildFly also allows us to use the environment variables as following  ${env.DB_CONNECTION_URL} :

           

                  <subsystem xmlns="urn:jboss:domain:datasources:4.0">
                      <datasources>
                          <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
                                   <connection-url>${env.DB_CONNECTION_URL}</connection-url> 
                                  <driver>mysql</driver> 
                                  <security> 
                                          <user-name>${env.DB_USERNAME}</user-name>
                                         <password>${env.DB_PASSWORD}</password> 
                                 </security>
          
          

           

          You can see the following link which explains how we can use it in OpenShift :  JBoss EAP Environment Variables | OpenShift Developers      You can do it on your local system as well.

           

          Regards

          Jay SenSharma

          • 2. Re: Configuring a datasource in Wildfly using environment variables for Docker
            damaru

            Wow, that's great, thanks. I tried it and it works.

             

            That will save me a ton of headaches!