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?
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.