How to set JVM settings in Dockerfile
Asked Answered
W

2

9

I have a Dockerfile looks like below:

FROM tomcat:9.0.12-jre8
EXPOSE 8080
COPY app.war "$CATALINA_HOME"/webapps

I need to set some JVM properties as below:

-DTOMCAT=Y
-Doracle.server=1234
-Doracle.url=1234
-Doracle.password=1234
...

How do I add these properties in Dockerfile?

Walters answered 22/7, 2019 at 21:22 Comment(0)
S
11

You can simply set the JAVA_OPTS value to the one you need at build time, in your Dockerfile :

ENV JAVA_OPTS="-DTOMCAT=Y -DOracle.server=1234 [...]"

You may also simply set it a runtime if you don't modify the CMD from the official tomcat image:

$ docker run -e JAVA_OPTS="-DTOMCAT=Y -DOracle.server=1234 [...]" your_image:your_tag 

See: https://github.com/docker-library/tomcat/issues/8

Considering the options you're providing in your example, it would be better to opt for the second version (host, port and password information should not be left in a Docker image, from a security standpoint).

If you're only providing minimal requirements, resource-wise, for your application, this could live in the Dockerfile.

Strontia answered 22/7, 2019 at 21:36 Comment(0)
E
4

The use case you show seems more like environment variables. You can have your application read those values from env variables and you can set them at runtime.

$ docker run --env MYVAR2=foo

Encephalic answered 22/7, 2019 at 21:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.