Reputation: 21
I am running multiple Docker containers with bitnami/tomcat
image and I want to share the configuration read only across all instances.
Every instance will contain this same configuration like specific libraries, datasources and so on. I already have proved and tested configuration that is being used in physical tomcat servers. I see this configuration can be ready before any instance is run.
The application can be deployed to every instance (copied once actually since configuration is shared) and it can be done by copying the WAR file to host folder ${persistence_path}/tomcat/data
that points to /bitnami
folder in container, provided I use
-v ${persistence_path}:/bitnami
when running the instance.
The question
I am looking for an reproducible way of creating instances so it would be by script or dockerfile rather than commiting a new image, since it does not provide a reliable record of how the image was created. By using the former I avoid the chance of images getting corrupt or lost in production.
Can I even share the configuration in multiple instances, as described?
Is this the best approach given I will not be modifying any tomcat settings after instances are started and if so I can re-run the instances with the new configuration as to change once and reflect in every instance?
Can it be done with a dockerfile instead of a set of commands? I don't think -v
is fully interchangeable with VOLUME
.
Upvotes: 0
Views: 692
Reputation: 11
The bitnami/tomcat
image uses a simple mechanism in order to decide whether restore data from a volume or initialize a volume.
On startup the container will check if a /bitnami/tomcat/.initialized
file exists.
/opt/bitnami/tomcat/{conf,data}
folders to the volume (this happens at first run). Then, it will link the original folders to the ones in the volume.Tomcat folder after first run:
root@2346ab1f5c88:/# ls -la /opt/bitnami/tomcat/{conf,data}
lrwxrwxrwx 1 root root 20 Sep 28 13:49 /opt/bitnami/tomcat/conf -> /bitnami/tomcat/conf
lrwxrwxrwx 1 root root 20 Sep 28 13:49 /opt/bitnami/tomcat/data -> /bitnami/tomcat/data
Therefore, the volume structure follows the following schema.
root@2346ab1f5c88:/# tree -L 1 -a /bitnami/tomcat
/bitnami/tomcat
├── conf
├── data
└── .initialized
2 directories, 1 file
If you want to add your own configuration you should either override the default configuration in /bitnami/tomcat/conf
after the Tomcat initialization takes place (at runtime) or override the default configuration in /opt/bitnami/tomcat/conf
at build time.
This means you could either:
bitnami/tomcat
and copy your configuration to /opt/bitnami/tomcat/conf
.app-entrypoint.sh
file to override the /bitnami/tomcat/conf
folder with it.docker cp
)Upvotes: 1
Reputation: 16294
You can mount a directory as read-only using the :ro
option of -v
docker run -v /your/host/dir:/bitnami:ro YOUR_IMAGE
You can create your own tomcat image starting from bitnami/tomcat
including copying your artifacts and configuration at image build time. Then you can override them at runtime using the -v
options.
If you want immutable containers (build time data locked in) you should build an image for every service you have. Otherwise you can use the volume binding approach, as described in the image description.
Upvotes: 1