Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add file to docker container to be used during startup

Is it possible to provide a file to a docker container during the run operation to be used during startup of the container?

Essentially I want to provide a txt file similar to plugins.txt in jenkins docker to a tomcat server. That file should contain names and versions (name:version) of .war and .jar files to be downloaded during startup of the container. I expect of this setup to be more flexible to provide customized containers for customers rather than having customer specific images. But the big questions for me are:

  1. Can I provide such a file during startup of a container?
  2. How should I handle versioning of the file and/or container to be able to check what the customer specific container contains?
  3. Is there anything else I should consider?
like image 335
st.huber Avatar asked Nov 29 '25 02:11

st.huber


1 Answers

You can mount individual files into a container as a volume:

docker run -v `pwd`/conf.txt:/app/conf.txt my_app

That needs to be run on the docker host itself, or under a User directory on Windows/MacOS. You can also create a named volume in docker where you can store these files and update via temporary containers.

With those volume mounts, you do need to be careful with permissions, uid's inside the container may not match your uid on the host. You also have the ability to mount the files read only with a simple :ro appended to the volume mount.

like image 194
BMitch Avatar answered Dec 02 '25 00:12

BMitch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!