Build and Configure Plugins Inside Solr Using Docker
Oct 01, 2019 · 3 Min Read · 3 Likes · 0 CommentAdding 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
WORKDIR /app
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/
EXPOSE 8983
CMD ["solr-precreate", "gettingstarted"]
Explanation
Let us go through the Dockerfile
:
We will be using a
Maven based Docker
image(using alpine to make it lightweight) for building the package. You can useGradle based image
as well if we are using gradle building system.Then we use
/app
directory as work directory and inside that we will copy thepom.xml
.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.Then we add the source directory in docker and build the
jar
file.Finally, we copy the jar file to Solr container at directory
/opt/solr/dist
.We will be using
solr-precreate
command, which will create a core namedgettingstarted
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"
services:
solr:
container_name: my_solr
build:
context: .
dockerfile: ./Dockerfile
image: my_solr
volumes:
- "./solrdata/:/var/solr/"
ports:
- "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: Jul 13, 2024
I won't spam you. Unsubscribe at any time.