cucucool
cucucool

Reputation: 3887

Use a configuration file from the host when building a Docker image

I am trying to build one image for tomcat server via docker file. When building it, i would like to copy a configuration file say users.xml from the current host directory to the tomcat image built.

I would like to know whether what i am trying to do makes sense and if yes, how do i do that ?

Upvotes: 1

Views: 2871

Answers (2)

Abhishek Galoda
Abhishek Galoda

Reputation: 3054

This worked for me

FROM tomcat:8.0.20-jre8
ADD server.xml /usr/local/tomcat/conf
COPY /target/webapp.war /usr/local/tomcat/webapps/ 

I was adding this customised server.XML to replace the TOMCAT native server.xml

Upvotes: 0

mbarthelemy
mbarthelemy

Reputation: 12913

Copying files from the host into the image during the build makes sense, yes.

You don't say what you've tried so far, but you can use the ADD and COPYinstructions in your Dockerfile to add your users.xml configuration file to the image. Have a look at the official documentation.

Just make sure everything is clear : when adding/copying files during build, these files must be on the host where you ran the docker build command, which may be different from the the host where the Docker server runs.

Also, the file to copy/add must be in the directory containing the Dockerfile, or inside a sub-directory, but cannot be located in any upper-level directory.

Note that the ADD command also lets you insert files from an external source (http(s)).

Upvotes: 2

Related Questions