By default the solr containers that get started will be assigned 512MB of memory.  
For the project we are migrating we have several custom indexes and we could use some more memory when all those need to be reindexed.

After a short investigation round, I found my way around to increase it.
There could be better/other ways to do this. If you know, please let me know!

I've configured it to be 1.5GB. This setting can be configured however you want off course.

My solution was to override the Start.ps1 script that gets executed once the Sitecore nonproduction Solr container starts.

The most important task of that PowerShell script is c:\solr\bin\solr.cmd start -port $SolrPort -f

With a custom DockerFile, we can overwrite that file and set the memory to the amount that we want:

c:\solr\bin\solr.cmd start -port $SolrPort -f -m 1536m

The process

I created my solr build folder and added the Dockerfile and Start.ps1 script.  
Where I got that script? From the image itself. Read here how you can do this

The Dockerfile doesn't do that much, it will only copy the Start.ps1 file and override the file that is already in the Base Image.

# escape=`

ARG BASE_IMAGE

FROM ${BASE_IMAGE}

SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]

COPY Start.ps1 C:\Start.ps1

This is the complete Start.ps1 script. Notice the -m flag in the last line.

param(
    [Parameter(Mandatory = $true)]
    [ValidateScript( { Test-Path $_ -PathType 'Container' })]
    [string]$InstallPath,
    
    [Parameter(Mandatory = $true)]
    [ValidateScript( { Test-Path $_ -PathType 'Container' })]
    [string]$DataPath,

    [Parameter(Mandatory = $true)]
    [string]$SolrPort
)

$dataPathToTest = Join-Path $DataPath solr.xml
if (Test-Path $dataPathToTest) {
    Write-Host "INFO: Existing Solr configuration found in '$DataPath'..."
}
else {
    Write-Host "INFO: Solr configuration not found in '$DataPath', copying clean configuration..."
    Copy-Item $InstallPath\** $DataPath -Recurse -Force -ErrorAction SilentlyContinue
}

c:\solr\bin\solr.cmd start -port $SolrPort -f -m 1536m

Off-course don't forget that your docker-compose.override.yml file needs to reference the build context (the folder that contains the Dockerfile).

 # Mount our Solr data folder
  solr:
    build:
      context: ./docker/build/solr
      args:
        BASE_IMAGE: ${SITECORE_DOCKER_REGISTRY}nonproduction/solr:8.4.0-${SITECORE_VERSION}
    mem_limit: 2GB
    volumes:
      - ${LOCAL_DATA_PATH}\solr:c:\data

Next, is to build the image: docker-compose build --no-cache

And spin everything up. And you'll get a solr running with the amount of memory that you wanted!


This was tested with the following Sitecore docker image: scr.sitecore.com/sxp/nonproduction/solr:8.4.0-10.1.0-ltsc2019