Here's my docker image. I want to override the default environment variables being set below from whatever is passed in the docker run command mentioned in the end
FROM ubuntu:16.04
ADD http://www.nic.funet.fi/pub/mirrors/apache.org/tomcat/tomcat-8/v8.0.48/bin/apache-tomcat-8.0.48.tar.gz /usr/local/
RUN cd /usr/local && tar -zxvf apache-tomcat-8.0.48.tar.gz && rm apache-tomcat-8.0.48.tar.gz
RUN mv /usr/local/apache-tomcat-8.0.48 /usr/local/tomcat
RUN rm -rf /usr/local/tomcat/webapps/*
ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64
ENV CATALINA_HOME /usr/local/tomcat
ENV CATALINA_BASE /usr/local/tomcat
ENV PATH $PATH:$JAVA_HOME/bin:$CATALINA_HOME/bin
ENV dummy_url defaulturl
ENV database databasedefault
COPY my.war /usr/local/tomcat/webapps/
RUN echo >> /usr/local/tomcat/conf/test.properties
RUN echo dummy_url =$dummy_url >> /usr/local/tomcat/conf/test.properties
RUN echo database =$database >> /usr/local/tomcat/conf/test.properties
ENTRYPOINT ["catalina.sh", "run"]
To run in local :
docker run -p 8080:8080 -e dummy_url=http:google.com -e database=jdbc://mysql allimages/myimage:latest
dummy_url and database do not seem to be getting overridden in the file that I am adding them in - test.properties. Any ideas would be greatly appreciated.
That means overriding an image file (
/usr/local/tomcat/conf/test.properties
) when running the image as a container (docker run
), not building the image (docker build
and its--build-args
option and itsARG
Dockerfile entry).That means you create locally a script file which:
/usr/local/tomcat/conf/test.properties
catalina.sh run $@
(see also "Store Bash script arguments $@ in a variable" from "Accessing bash command line args$@
vs$*
")That is:
You would modify your Dockerfile to
COPY
that script and call it:Then, and only then, the
-e
options of docker run would work.You are confusing what gets executed when building the image and what gets executed when starting the container. The
RUN
command inside the dockerfile is executed when building the image, when runningdocker build ...
Thus when the above execute the file
test.properties
will contain the default values specified in the Dockerfile.When you execute
docker run -p 8080:8080 -e dummy_url=http:google.com -e database=jdbc://mysql allimages/myimage:latest
theENTRYPOINT ["catalina.sh", "run"]
will get executed with env valuesdummy_url=http:google.com
anddatabase=jdbc://mysql
.You can allow values in test.properties to be ovveriden using:
$dummy_url >> /usr/local/tomcat/conf/test.properties
and$database >> /usr/local/tomcat/conf/test.properties
to the start ofcatalina.sh
script.And when building the image override the values using
docker build --build-arg dummy_url_arg=http:google.com --build-arg database_arg=jdbc://mysql allimages/myimage:latest ...