Apache Solr and Docker

Reference notes on running SolrCloud in Docker on Ubuntu Linux.

Solr works best on Linux, so start with a Linux base platform. Check the Docker documentation for other distros. After the OS is up and running, install the Docker Engine and Docker Compose.

Install Docker Engine

https://docs.docker.com/engine/install/ubuntu/

Install Docker Compose

https://docs.docker.com/compose/install/

Install Solr in Docker Container

https://hub.docker.com//solr/">https://hub.docker.com//solr/

Run demo image from Docker Registry
sudo -i
docker run -p 8983:8983 -t solr

Install Solr Cloud in Docker Container

Variation 1

Create a plain 3-node Solr Cloud / Zookeeper cluster following online docker-compose example:
mkdir /opt/mycluster
cd /opt/mycluster
curl --output docker-compose.yml
docker-compose up -d

Variation 2

But research suggests running multiple Solr instances in a Docker container on single Virtual Machine results in faster query response times than single Solr instance on bare metal server. Therefore, create a 3-node Solr Cloud / Zookeeper cluster with volumes for persisting data. Save below YAML as docker-compose.yml.

version: '3.7'
services:
  solr1:
    image: solr:latest
    container_name: solr1
    ports:
     - "8981:8983"
    environment:
      - ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181
    networks:
      - solr
    volumes:
      - data1:/var/solr
    depends_on:
      - zoo1
      - zoo2
      - zoo3

  solr2:
    image: solr:latest
    container_name: solr2
    ports:
     - "8982:8983"
    environment:
      - ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181
    networks:
      - solr
    volumes:
      - data2:/var/solr
    depends_on:
      - zoo1
      - zoo2
      - zoo3

  solr3:
    image: solr:latest
    container_name: solr3
    ports:
     - "8983:8983"
    environment:
      - ZK_HOST=zoo1:2181,zoo2:2181,zoo3:2181
    networks:
      - solr
    volumes:
      - data3:/var/solr
    depends_on:
      - zoo1
      - zoo2
      - zoo3

  zoo1:
    image: zookeeper:latest
    container_name: zoo1
    restart: always
    hostname: zoo1
    ports:
      - 2181:2181
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=0.0.0.0:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=zoo3:2888:3888;2181
    networks:
      - solr

  zoo2:
    image: zookeeper:latest
    container_name: zoo2
    restart: always
    hostname: zoo2
    ports:
      - 2182:2181
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=0.0.0.0:2888:3888;2181 server.3=zoo3:2888:3888;2181
    networks:
      - solr

  zoo3:
    image: zookeeper:latest
    container_name: zoo3
    restart: always
    hostname: zoo3
    ports:
      - 2183:2181
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888;2181 server.2=zoo2:2888:3888;2181 server.3=0.0.0.0:2888:3888;2181
    networks:
      - solr

networks:
  solr:

volumes:
  data1:
  data2:
  data3:

Add the Solr Getting Started collection, and populate it with data:
sudo docker exec -it --user=solr solr1 bin/solr create_collection -c gettingstarted
sudo docker exec -it --user=solr solr1 bin/post -c gettingstarted example/exampledocs/manufacturers.xml

Add the Data Import Handler collection:
sudo docker exec -it --user=solr solr1 bin/solr create_collection -c dih

References

Docker-Solr FAQ
https://github.com/docker-solr/docker-solr/blob/master/Docker-FAQ.md#can-i-run-zookeeper-and-solr-clusters-under-docker

Docker-Solr Builds
https://github.com/docker-solr/docker-solr
https://hub.docker.com//solr/">https://hub.docker.com//solr/

Docker-Solr Documentation
http://docs.docker.oeynet.com/samples/library/solr/

Solr Data Import Handler
https://lucene.apache.org/solr/guide/8_5/uploading-structured-data-store-data-with-the-data-import-handler.html#uploading-structured-data-store-data-with-the-data-import-handler