Skip to main content

Using multiple Solr cores with DDEV

Published on

If you want to have multiple Solr indexes using Search API, you need to have a core for each index instance. For my local development stack, I use DDEV. The documentation has a basic example for setting up a Solr service, but I had quite the fun time figuring out how to ensure multiple cores.

After reading the Solr image for Docker, I discovered you can override the container's command and pass additional commands as well. I found the issue "Create multiple collections at startup" from Sep 2017 which summed up my desired outcome. You just need to add this as the command for your container to generate additional cores:

bash -e -c "precreate-core collection1; precreate-core collection2; solr-foreground"

This ensures collection1 and collection2 and could create however many are needed. 

To add Solr to your DDEV with multiple cores, here is the docker-composer.solr.yaml you can add to your project

version: '3.6'

    container_name: ddev-${DDEV_SITENAME}-solr
    image: solr:6.6
    command: 'bash -e -c "precreate-core collection1; precreate-core collection2; solr-foreground"'
    restart: "no"
      - 8983
    labels: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT $DDEV_URL
      - HTTP_EXPOSE=8983
      - "./solr:/solr-conf"
      - solr:$DDEV_HOSTNAME
      # hostname alias
      - solr:solr.internal


I'm available for one-on-one consulting calls – click here to book a meeting with me 🗓️