Build and Configure Plugins Inside Solr Using Docker

Build and Configure Plugins Inside Solr Using Docker

Adding a plugin to Solr is relatively simple process. In this article, we are going to see how to add a plugin by creating a jar file using a docker container, then add that to a Solr which also runs inside docker container.

Building the plugin

Workflow for building the plugin

Steps for building a Solr plugin inside Solr docker file are like this:


Example of solr image

Here is an example to build a Solr plugin using Maven in Docker:

FROM maven:alpine as build
COPY /PLUGIN_DIR/pom.xml .
RUN mvn dependency:go-offline
COPY /PLUGIN_DIR/src /app/src
RUN mvn package

FROM solr:slim
COPY --from=build /app/target/*.jar /opt/solr/dist/
CMD ["solr-precreate", "gettingstarted"]


Let us go through the Dockerfile:

  1. We will be using a Maven based Docker image(using alpine to make it lightweight) for building the package. You can use Gradle based image as well if we are using gradle building system.

  2. Then we use /app directory as work directory and inside that we will copy the pom.xml.

  3. After that, we will install dependencies using mvn dependency:go-offline command. Reason for using this instead of clean is that, this step will be cached next time we build the image, which will reduce the building time a lot.

  4. Then we add the source directory in docker and build the jar file.

  5. Finally, we copy the jar file to Solr container at directory /opt/solr/dist.

  6. We will be using solr-precreate command, which will create a core named gettingstarted if it does not exist.

Run solr

Without docker-compose

If you don’t use docker compose, then you can use the following instructions:

Build the docker image using:

docker build . -t my_solr

Then run it:

mkdir solrdata
docker run -d -v "$PWD/solrdata:/var/solr" -p 8983:8983 my_solr

Then the Solr will be running with core gettingstarted. Solr data will be shared with your local machine with solrdata directory(through volume).

With docker-compose

docker-compose.yml should contain the following service:

version: "3"

    container_name: my_solr
      context: .
      dockerfile: ./Dockerfile
    image: my_solr
      - "./solrdata/:/var/solr/"
      - "8983:8983"

Then you can build the image by:

docker-compose -f docker-compose.yml build solr

Then run the service by:

docker-compose -f docker-compose.yml up

Configure plugin inside docker

FYI: This step will vary from solr to solr based on its configuration, but the idea of using the plugin is almost same for any solr standalone mode.

We need to load the plugin inside the core by putting the following line in data/gettingstarted/conf/solrconfig.xml inside solrdata volume.

<lib dir="${solr.install.dir:../../../..}/dist/" regex="*.jar" />

Thats it, the plugin will be loaded in that core. Now you need to restart the solr to make the plugin usable.

In conclusion

Thank you for reading. Please use the comment section below if you have any feedback on this setup. Cheers!!

Last updated: May 22, 2024

← Previous
Use VS Code Inside Docker Container for Development

VS Code is the most popular IDE at the moment. You can use it for developing applications in almost …

Next →
Django Access URL Arguments Through Middleware

Lets say you have an API which is being used by many stores. Now for a specific store ABC, they want …

Share Your Thoughts
M↓ Markdown