Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

Using multiple Solr cores with DDEV

Parent Feed: 

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'

services:
  solr:
    container_name: ddev-${DDEV_SITENAME}-solr
    image: solr:6.6
    command: 'bash -e -c "precreate-core collection1; precreate-core collection2; solr-foreground"'
    restart: "no"
    ports:
      - 8983
    labels:
      com.ddev.site-name: ${DDEV_SITENAME}
      com.ddev.approot: $DDEV_APPROOT
      com.ddev.app-url: $DDEV_URL
    environment:
      - VIRTUAL_HOST=$DDEV_HOSTNAME
      - HTTP_EXPOSE=8983
    volumes:
      - "./solr:/solr-conf"
  web:
    links:
      - solr:$DDEV_HOSTNAME
      # Platform.sh hostname alias
      - solr:solr.internal

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web