Passing Tomcat parameters to Docker Passing Tomcat parameters to Docker docker docker

Passing Tomcat parameters to Docker


The typical method for docker containers is passing via environment variables.

Expanding on a solution to pass the port via command line the server.xml needs to be modified so it takes in properties from JAVA_OPTS

For example in server.xml

<GlobalNamingResources>    <Resource Name="jdbc/Addresses"        auth="Container"        type="javax.sql.Datasource"        username="auser"        password="Secret"        driverClassName="com.mysql.jdbc.Driver"        description="Global Address Database"        url="${jdbc.url}" /></GlobalNamingResources>

Then you can pass value of ${jdbc.url} from properties on the command line.

JAVA_OPTS="-Djdbc.url=jdbc:mysql:mysqlhost:3306/"

When running the docker image you use the -e flag to set this environment variable at run time

$ docker run -it -e "JAVA_OPTS=-Djdbc.url=jdbc:mysql:mysqlhost:3306/" --rm myjavadockerimage /opt/tomcat/bin/deploy-and-run.sh

Optionally also add a --add-host if you need to map mysqlhost to a specific ip address.


There are at least two options I can think of:

  • If server.xml supports environment variables, you could pass database connection details to the container via --env or even --env-file. Note that this has certain security implications.
  • Another option would be to mount server.xml for a particular instance into the container via --volume.