Merging Configuration Files from Persistent External Storage
You can provide your own application configuration by making the contents of a directory on the host machine available as external storage at the given directory within the container. This can also be done in Kubernetes with a ConfigMap that creates persistent storage access as specified in a YAML manifest file.
In both of these scenarios the original version of the internal container directory is overridden. This can cause an issue if the Docker image contained any default configuration within this directory. If you mount external storage as /opt/mtx/conf, for example, the external directory must include any files that were already present in that directory.
To merge the contents of external storage without overwriting, subdirectories of the /sync directory are provided. Files in those subdirectories are automatically merged with the existing files in the target directory at startup, as shown in Figure 1.
When a MATRIXX Java-based Docker container starts, it automatically merges the contents of the sync directory with the /opt/mtx directory in the container using rsync. Merging overwrites existing files with matching file names; it does not merge file contents. Subdirectories are also merged in the same way.
Auto-Merged Persistent Storage Directory Mapping shows how subdirectories of the /sync directory are mapped.
Mount Point | Target Directory |
---|---|
/sync/conf | /opt/mtx/conf |
/sync/data | /opt/mtx/data |
/sync/bin | /opt/mtx/bin |
/sync/ext | /opt/mtx/ext |
/sync/lib | /opt/mtx/lib |
The echo -e command below creates an application configuration file payment-service.yaml in the conf directory, outside of the container:
mkdir conf
cd conf
echo -e "spring:\n activemq:\n brokerUrl: tcp://activemqhost:61616\n" > payment-service.yaml
cd ..
The following docker run command runs the
payment-service
Docker container with the conf
directory mounted by the container as /sync/conf:
docker run -p 9095:9095 -v `pwd`/conf:/sync/conf payment-service:5200
The payment-service.yaml file in the conf directory is accessed by the container in the /sync/conf directory, and the contents of that mount point are merged with /opt/mtx/conf.