Passing environment variables to a docker image to a file in tomcat

Expected behavior

When passing Environment variables via docker -d -e var1=value1 -e var2=value2 -e var3=value3 image_tag_name
It should pass those variables to container and whichso ever file we are using them like in if we use /usr/local/tomcat/webapps/applicationname/context/class/

and run smoothly

Actual behavior

docker -d -e var1=value1 -e var2=value2 -e var3=value3 image_tag_name
if not setting value in file


while passing environment variables in they are not getting reflected.

But when i exec the container i am able to see environment variable set in container.
using docker exec -it container id sh
and then env to show environment variables.
entries in
database host = ${DB_HOST}
database username = ${DB_USER}
database password = ${DB_PASSWORD}

Variables passed are of database host name, userid and password .

Tomcat does not pass environment variables to an Application that way.

You need to specify the environment variables in the script (Linux) or setenv.bat (Windows).


export DB_HOST="myhost"
export DB_USER="my-user"
export DB_PASSWORD="secret"

And your Java Application must retrieve them from environment variables.


You can then map that file as a volume to the container.


For more reference:

Deploying a Java Tomcat App stack with environment variables

The Java Application Code example