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?

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.