How to Run Old Versions of Solr in a Docker Container

Index
The Scenario
Let's say that you have a production site in Azure running Solr on a virtual machine. The indexes are located in C:\Solr\solr-x.x.x\server\solr. You want to get this running on your local machine without having to install yet another version of Solr, so you decide to use Docker. Nothing fancy... No SolrCloud, no HTTPS. Just a simple install of Solr x.x.x running in a Docker container.
Getting Started
In the upstream C:\Solr\solr-x.x.x\server\solr directory you might have these folders:
- sitecore_master_index- sitecore_web_index- sitecore_core_index- client_custom_indexZip up all the index folders. You don't need to include the data folders within each index folder, as they will be created by Solr when it starts up. But in my experience, you can.
While being mindful of potential egress fees from where you are hosting the zip file, copy the zip to your local machine. Unzip it wherever you like. Perhaps you might even want to unzip it within your project directory and add the core.properties file and the conf folder to source control?
Now let's set up the Docker configuration.
Docker Compose
Create a file called docker-compose.yml in the root of your project:
version: '3.6'
services: solr: build: context: .\docker\build\solr image: solr scale: 0 hostname: "solr" ports: # TODO: update this port as desired. Maybe write something fancy like a init.ps1 that populates a .env with your specific directory path and consume it here... - "8983:8983" volumes: # TODO: update this path as needed - C:/projects/My-Project/solr:C:/solr/server/solrDocker File
Create a directory called /docker/build/solr and create a file called Dockerfile within it:
# escape=`
FROM mcr.microsoft.com/powershell:nanoserver-1809
# Install Amazon Corretto (Java)RUN curl.exe -L -o jre.zip https://corretto.aws/downloads/latest/amazon-corretto-8-x64-windows-jre.zip && ` mkdir C:\jre && ` tar.exe -xf jre.zip -C C:\jre --strip-components=1 && ` del jre.zip
USER ContainerAdministratorRUN SETX /M JAVA_HOME "C:\jre" && ` SETX /M PATH "%PATH%;%JAVA_HOME%\bin"USER ContainerUser
# Install Solr# TODO: replace your version of Solr hereRUN curl.exe -L -o solr.zip https://archive.apache.org/dist/lucene/solr/x.x.x/solr-x.x.x.zip && ` mkdir C:\solr && ` tar.exe -xf solr.zip -C C:\solr --strip-components=1 && ` del solr.zip
# Solr configurationCOPY ./solr.in.cmd C:\solr\bin\
# TODO: consume port from .envEXPOSE 8983
HEALTHCHECK CMD powershell -command ` try { ` $response = iwr http://localhost:8983; ` if ($response.StatusCode -eq 200) { return 0} ` else {return 1}; ` } catch { return 1 }
COPY ./start.cmd /ENTRYPOINT ["start.cmd"]Solr Configuration Files
Create a file called solr.in.cmd and place it in the same directory as your Dockerfile:
@echo off
REM Increase Java Min/Max Heap as needed to support your indexing / query needsset SOLR_JAVA_MEM=-Xms1g -Xmx1g
REM Enables HTTPS. It is implicitly true if you set SOLR_SSL_KEY_STORE. Use this configREM to enable https module with custom jetty configuration.set SOLR_SSL_ENABLED=false
REM Require clients to authenticateset SOLR_SSL_NEED_CLIENT_AUTH=false
REM Enable clients to authenticate (but not require)set SOLR_SSL_WANT_CLIENT_AUTH=false
REM Verify client hostname during SSL handshakeset SOLR_SSL_CLIENT_HOSTNAME_VERIFICATION=false
REM SSL Certificates contain host/ip "peer name" information that is validated by default. SettingREM this to false can be useful to disable these checks when re-using a certificate on many hostsset SOLR_SSL_CHECK_PEER_NAME=falseCreate a file called start.cmd and place it in the same directory as your Dockerfile. Here's what it will look like:
REM Start Solr in foregroundC:\solr\bin\solr start -p 8983 -fup.ps1
As a little bit of extra fanciness, we can start to make this idiot proof and do a check to ensure that the 8983 port isn't already listening with a process on your host machine. If it is, we can prompt the user to kill it. This is useful if you have multiple projects running on your local machine and you don't want to have to remember which one is using the port.
From there, we build and run the container, and then open the Solr admin site.
Create a file called up.ps1 in the root of your project:
$process = Get-NetTCPConnection -LocalPort 8983 -State Listen -ErrorAction SilentlyContinue | Select-Object -ExpandProperty OwningProcess | Get-Process
if ($process) { Write-Host "Process $($process.ProcessName) with ID $($process.Id) is using the port that the solr container needs: 8983"
# Prompt the user for confirmation $confirmation = Read-Host "Do you want to kill this process? (y/n)"
if ($confirmation -eq 'y') { # Kill the process Stop-Process -Id $process.Id -Force Write-Host "Process $($process.ProcessName) with ID $($process.Id) has been killed." -ForegroundColor Green } else { Write-Host "No action taken." }}else { Write-Host "No service is running on port: 8983. Continuing..." -ForegroundColor Green}
docker compose builddocker compose up -d
Write-Host "Done! Remember to populate solr managed schema and reindex if needed." -ForegroundColor Green
Write-Host "Opening solr admin site..." -ForegroundColor GreenStart-Sleep -Seconds 10Start-Process http://localhost:8983/solr/#/Build and Run
From the root of your project, run .\up.ps1.
When the Solr admin site loads up, you should see your cores listed. You might need to wait a while for Solr to initialize, so if the interface looks broken or some cores are missing, just wait a bit and refresh. You can also check the logs by running docker compose logs -f from the root of your project.
Final Steps
Update your ConnectionStrings.config like so:
<add name="solr.search" connectionString="http://localhost:8983/solr" />From there, populate the Solr managed schema and reindex if needed.
Keep going FAST,
MG





