Dockerizing solr

I created a solr dockerfile, for the solr version 9.1.1
I copied some python scripts into docker container, and i gave command to start solr and run one python script.
but the problem is that when python script executes completely container stops. But i want that solr should remain active until i stop the container.
Those python scripts are processing some data then uploading on solr

This is my dockerfile :

FROM solr:9.1.1

USER root

RUN apt-get update && apt-get install -y nano procps python3-pip &&
mkdir -p /opt/alok &&
chown -R solr:solr /opt/alok

COPY requirements.txt /opt/alok/
COPY ./scripts/ /opt/alok/

RUN pip3 install -r /opt/alok/requirements.txt

RUN mkdir -p /var/solr/data && chown -R solr:solr /var/solr
COPY ./conf/managed-schema /opt/solr/server/solr/configsets/_default/conf/managed-schema
COPY ./conf/solrconfig.xml /opt/solr/server/solr/configsets/_default/conf/solrconfig.xml

WORKDIR /opt/alok

and this is compose file :

version: ‘3’
services:
solr:
build: .
ports:
- “8983:8983”
volumes:
- ./data/:/var/solr/data/
- ./scripts/:/opt/alok/
command: bash -c “cd …/solr-9.1.1/bin/ && ./solr start -force & cd …/scripts/ && python3 -B automation.py”

Your command needs to create a foreground process. Otherwise, the container will start and stop after the last process is terminated. Since you send solr to the background it will not keep the container running.

Though, It appears that you mix a backend component and some application logic. Why don’t you separate them into individual images? Use an existing solr image as is and create an image just for your application?