Docker + Tomcat + .properties - Environment Variables

I need to deploy a tomcat server setting the MySQL database url inside

/META-INF/config.properties

to the docker file. As we deploy these containers, IP addresses cannot be hardcoded in the program.

Is there any way to output environment variables from the system inside this file? I would like to do something like this:

mdms.db.url=jdbc:mysql://**${MYSQL_HOST}**/db_mdms?useEncoding=true&characterEncoding=UTF-8&autoReconnect=true mdms.db.username=root mdms.db.password=thesecretsauce

I searched the internet and found that I need to install some kind

-DMYSQL_HOST=$MYSQL_HOST

when starting the application, but starting tomcat with this flag did not do this trick, and I could not get it to work.

One more thing I tried:

<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> <property name="locations" value="/WEB-INF/config.properties"/> <property name="ignoreResourceNotFound" value="true" /> <property name="searchSystemEnvironment" value="true" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> </bean>

although this does not seem to do the trick :(

I also tried both in combination with each other.

I am running Linux Xubuntu programming in Netbeans (although I figured out how to deploy tomcat without netbeans if necessary)

I am not the author of the application; and I'm not very sure about Tomcat / Java web applications. However, this needs to be done, and there is a language barrier (or rejection, I have not figured it out yet), preventing me from forcing the author to fix it for me.

Thanks for any help! -Paul

+5
source share
1 answer

How I managed to solve this problem is to set CATALINA_OPTS in the DockerFile:

 ENV CATALINA_OPTS="-Dkey=value" 

For example, the entire DockerFile for my application would look like this:

 FROM tomcat:8.0-jre8 ENV spring.profiles.active=dev ENV CATALINA_OPTS="-Dkey=value" ADD myWar.war /usr/local/tomcat/webapps/ CMD ["catalina.sh", "run"] 
+7
source

Source: https://habr.com/ru/post/1235417/


All Articles