docker build question?

Soldato
Joined
9 Mar 2012
Posts
10,075
Location
West Sussex, England
I'm learning docker and would like to use the official tomcat image as the starting point in my Dockerfile but it has an env variable set for CATALINA_HOME = /usr/local/tomcat.

The java WAR application I'd like to deploy would like to be installed in a different path to what is set upstream from the tomcat image.

Can I override the CATALINA_HOME env downstream in my Dockerfile to affect the location of where tomcat is installed?

I know I could copy all of the tomcat Dockerfile from github and make my changes that way but that seems a dirty solution. Just wondered if Docker had an override mechanism for this situation?
 
Yes you can override it in your Dockerfile as follows.

Code:
ENV CATALINA_HOME <insert your home dir>

Thanks, I get that works for the ENV variable values in my stage of the build but it doesn't effect what is done with the earlier value of an ENV declared upstream in the image you're basing your build off of.

e.g.

Code:
FROM tomcat:8.5.54-jdk8-openjdk

ENV CATALINA_HOME /home/user/folder1/folder2/folder3

CMD ["catalina.sh", "run"]


The docker build process builds the tomcat layer based on the FROM instruction and that image already sets CATALINA_HOME to /usr/local/tomcat.

So whilst you're correct that CATALINA_HOME in my build equals "/home/user/folder1/folder2/folder3" the purpose for changing it was to effect where the tomcat folder was built to including any permissions set on that folder during the tomcat build stage of the Dockerfile e.g. FROM.

If I try to move the ENV before the FROM line it causes an docker daemon error "No build stage in current context".
 
Why does the war file care where tomcat is installed to? Usually you just move it to $CATALINA_HOME/webapps.

If you want to move tomcat itself I don't see another option other than modifying the base tomcat dockerfile. That's quite unusual though and for a production application I wouldn't recommend it (you might might miss upstream changes later).
 
Back
Top Bottom