 [ ← blog / drupal ](/) Sep 21, 2018  ·  \#drupal  ·  2 min read 

# Using multiple Solr cores with DDEV



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](https://github.com/drud/ddev). The documentation has a [basic example for setting up a Solr service](https://ddev.readthedocs.io/en/latest/users/extend/additional-services/#apache-solr), but I had quite the fun time figuring out how to ensure multiple cores.

After reading the [Solr image for Docker](https://hub.docker.com/_/solr/), I discovered you can override the container's command and pass additional commands as well. I found the issue "[Create multiple collections at startup](https://github.com/docker-solr/docker-solr/issues/142)" 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

```yaml
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

```

 

  ![](/themes/custom/mglaman/images/headshot.webp)Thanks for reading

I write about Drupal, PHP, and the quiet infrastructure behind large sites — caching, config, and testing. New posts land every week or two.

 [Subscribe via RSS →](/rss.xml) [About me →](/about-me) 

 



 

  [← Older

Goodbye AdSense, hello CodeFund.

 ](/blog/goodbye-adsense-hello-codefund) [Newer →

Xdebug over the command line with DDEV

 ](/blog/xdebug-over-command-line-ddev)