Sitecore’s docker containers already ship with the possibility to add custom Solr indexes as described by Koen Heye.
However, this comes with certain limitations:
Index prefixes are restricted to “sitecore_” or “xdb_”
Even though there is a possibility to customize the base config’s xml files using xslt, we can’t use different config sets for individual indexes
We can’t alter certain files in the base config set (e.g. stopwords*.txt)
This blog post aims to get rid of those limitations. All the following code samples were developed and tested in Sitecore 10.2 and should be applicable for Sitecore 10.1+. Since the solr-init container was introduced in Sitecore 10.1 this approach won’t work prior to that version. It is also important to note that we are not going to alter existing functionality but rather put it on top.
Information structure
Before we start customizing any scripts, we want to define the information structure which tells the entrypoint script which indexes should be created and which config sets those indexes will use. For this purpose we are going to introduce two new json files (we will leave the cores*.json untouched to not break any standard functionality):
collections.json
Since Sitecore’s solr container runs in SolrCloud mode we are using the term “collections” to define our indexes. The first index “myclient_master_index” defines a new custom index with a custom config set. For custom indexes we also need to define an alias. The second index is an already existing one where we just want to update the config set. In this case no alias is needed since it will be automatically created by the base scripts of the solr-init container.
Place this files at /docker/build/solr-init/custom/data/collections.json
configs.json
In this file we define the config sets which need to be created (mycustomconfig) or altered (sitecore_* or xdb_*).
Place this files at /docker/build/solr-init/custom/data/configs.json
Provide custom configs sets
As you can see in the json file, the actual config set files will be placed under /docker/build/solr-init/custom/data/configs:
If you want to start based on the default config set provided by Sitecore you can just download it with the following script (btw, this is the Download-SolrConfig.ps1 which is available in the solr-init container). Make sure the solr container is running:
Add new functionality
Now we are ready to introduce new functionalty. As already mentioned, we won’t alter the existing Start.ps1 script and only build new functionality on top of it. Therefore we will introduce a new Start-Custom.ps1 which utilizes the standard Start.ps1 in it. This Start-Custom.ps1 will be later used as the new entry point for the solr-init container.
Start-Custom.ps1
This script first executes the standard Start.ps1 which creates all the standard indexes provided by Sitecore. Afterwards we add the following new parts:
Load configs from configs.json
Create or update all configs in Solr
Load collections from collections.json
Create new collections or reload existing ones in Solr
Place this script at /docker/build/solr-init/custom/Start-Custom.ps1
There are three additional scripts which are utilized in Custom-Start.ps1
Update-SolrConfig.ps1
Place this script at /docker/build/solr-init/custom/Update-SolrConfig.ps1
Reload-SolrCollection.ps1
This script is used to reload already existing indexes in case their config set had been updated before.
Place this script at /docker/build/solr-init/custom/Reload-SolrCollection.ps1
New-SolrCollection.ps1
Place this script at /docker/build/solr-init/custom/New-SolrCollection.ps1
Set a new entry point
Last step is to add Custom-Start.ps1 as the new entry point for the solr-init container. Therefore we need to customize the Dockerfile of the corresponding image.
Please note that this is the bare minimum which is needed. If you are using modules like SXA, this file may already exist and you just need to add the missing lines at the end of the script. An example can be found in the official Sitecore “docker-examples” repository on GitHub.
If the Dockerfile does not exist on your end, then create it at /docker/build/solr-init/Dockerfile. You will also need to add a new section to the docker-compose.override.yml file as shown here.
Closing thoughts
Now you are able to configure indexes with custom config sets in Docker containers. As this whole approach builds on top of the existing one, it should also be valid for future Sitecore versions.