clorz
clorz

Reputation: 1133

Handling configuration of tomcat apps inside a docker container

I've got an app that runs inside Tomcat app server. It has a bunch of settings that may change between environments. For example, database credentials or host/port of a remote API to use.

Their default values are baked into the .war file. Basically, they are in web.xml. What would be the best way to make them changeable through parameters to docker run?

So far I'm thinking about just making $CATALINA_HOME/conf into a volume and simply setting up context files on docker host. Maybe there's a better approach?

I can not find a way to use environment variables to configure tomcat. Do I have to change the app itself to read those vars?

To put it simply, what are the ways to customize tomcat apps inside docker without baking configs into the image itself at build time?

If it matters, I'm using official tomcat images from docker hub.

Upvotes: 1

Views: 1324

Answers (1)

Rawkode
Rawkode

Reputation: 22592

I solve this by passing through the environment variables at runtime, through swarm or docker run -e and use envsubstr in an entrypoint script to swap in what I need.

Dockerfile:

ENTRYPOINT: ["my_script"]

my_script:

envsubstr < server.dist.xml > server.xml
catalina.sh start

server.dist.xml:

<Resource name="jdbc/${DRIVER}" auth="Container"
              type="javax.sql.DataSource" driverClassName="${DRIVER_NAME}"
              url="${DRIVER_URL}"
              username="${NAME}" password="${PASSWORD}" maxActive="20" maxIdle="10"
              maxWait="-1"/> 

envsubstr is part of gettext, so ensure that's available within your images.

Upvotes: 1

Related Questions