Run Solr in Openshift

Get a running solr instance on Openshift with s2i images

Albert Lacambra BasilAlbert Lacambra Basil

Create docker file

FROM solr:8.2.0

MAINTAINER  Albert Lacambra Basil "albert@lacambra.tech"
USER root
ENV STI_SCRIPTS_PATH=/usr/libexec/s2i

LABEL io.k8s.description="Run SOLR search in OpenShift" \
      io.k8s.display-name="SOLR 6.6" \
      io.openshift.expose-services="8983:http" \
      io.openshift.tags="builder,solr,solr8.2.0" \
      io.openshift.s2i.scripts-url="image:///${STI_SCRIPTS_PATH}"

COPY ./s2i/bin/. ${STI_SCRIPTS_PATH}
RUN chmod -R a+rx ${STI_SCRIPTS_PATH}

# If we need to add files as part of every SOLR conf, they'd go here
# COPY ./solr-config/ /tmp/solr-config
# Give the SOLR directory to root group (not root user)
# https://docs.openshift.org/latest/creating_images/guidelines.html#openshift-origin-specific-guidelines

RUN chgrp -R 0 /opt/solr \
  && chmod -R g+rwX /opt/solr

RUN chgrp -R 0 /opt/docker-solr \
  && chmod -R g+rwX /opt/docker-solr

USER 8983

Build Dockerimage

#!/bin/bash
SCRIPT_DIR=$(dirname $0)

docker build -t 'alacambra/openshift-solr:8.2.0' -f ${SCRIPT_DIR}/Dockerfile ${SCRIPT_DIR}

Import ImageStream

oc import-image s2i-solr --from="alacambra/openshift-solr:8.2.0" --confirm

Create App

create new app with solr config files: lacambra.tech/blog-build/s2i-solr/solr
oc new-app s2i-solr:8.2.0~/{path/to/s2i-solr/solr/} --name=solr-blog

Reabuild app

rebuild app with solr config files: lacambra.tech/blog-build/s2i-solr/solr
oc start-build --from-dir . solr-blog

After update docker file or s2i scripts

./build.sh && \
docker push alacambra/openshift-solr:8.2.0 && \
oc import-image s2i-solr --from="alacambra/openshift-solr:8.2.0" --confirm && \
oc start-build --from-dir ./solr/ solr-blog

Send a query request

Response body:

{
    "responseHeader":{
        "status":0,
        "QTime":34,
        "params":{
            "q":"a"
        }
    },
    "response":{
        "numFound":0,
        "start":0,
        "docs":[
        ]
    }
}