Bharath Dasararaju
Bharath Dasararaju

Reputation: 525

update custom configuration file in Docker

I am new to Docker. My requirement is to create a docker file which should install Wildfly server, add war file to Wildfly, add custom property file (which contains db connection strings which will read by application)

My Docker file

FROM jboss/wildfly
Add application.properties /opt/jboss/
ADD spring_application.war /opt/jboss/wildfly/standalone/deployments/

application.properties

db_url = jdbc:mysql://**server host name**:**port**
db_username = **username**
db_password = **password**

Note: in the above file server host name, port, username, password should be dynamic

War file (spring rest application) will read parameters from application.properties

I am able successfully install Wildfly and deployed application. Now i need to pass parameters in application.properties at runtime. Please help me if anyone has solution.

Upvotes: 2

Views: 2257

Answers (1)

jazgot
jazgot

Reputation: 2063

You can do this by overwriting entrypoint script. Here is example run.sh script which creates application.properties file before booting application.

run.sh

#!/bin/bash -x
PROPERTIES=/opt/jboss/application.properties
echo "db_url = jdbc:mysql://${MYSQL_HOST}:${MYSQL_PORT}" > ${PROPERTIES}
echo "db_username = ${MYSQL_USER}" >> ${PROPERTIES}
echo "db_password = ${MYSQL_PASS}" >> ${PROPERTIES}
exec /opt/jboss/wildfly/bin/standalone.sh -b 0.0.0.0 $@

Dockerfile

FROM jboss/wildfly
ADD run.sh /run.sh
CMD /run.sh
ADD spring_application.war /opt/jboss/wildfly/standalone/deployments/

Run this with:

docker run -e MYSQL_HOST=mysqlhost -e MYSQL_USER=user -e MYSQL_PASS=pass wildflyimage

Upvotes: 2

Related Questions