Solr in Docker, How to create a distributed collection shared in mounted volume directory

3.4k views Asked by At

I am trying to set a cloud of solars within docker. I am using docker-compose to bring the cloud up. I create a cloud, containing 3 zookeepers, and 4 solrs (solr1, solr2, solr3, solr4) containers. Creation of distributed collection of 4 shards and 2 replicas is chill. The problem is when it goes to creation the collection in a mounted volume to have a backup at a machine outside the docker. I can mount the directory volume from machine to solr cloud for each container, but I can't create a collection there. When I create distributed collection by

docker exec -it solr1 /opt/solr/bin/solr create_collection -c publications -s 4 -rf 2 -p 8983

I have directories of two cores in containers, e.g. for solr1 there is

/opt/solr/server/solr/publications_shard2_replica_n6

and

/opt/solr/server/solr/publications_shard4_replica_n14

for shard2, I have I have a directories of two cores in containers, e.g. for solr1 there is

/opt/solr/server/solr/publications_shard1_replica_n1

and

/opt/solr/server/solr/publications_shard3_replica_n8

etc. The names of cores are dynamic.

How to have them created in my volume directory which is

/root/solr/cores

My docker-compose.yml is as follows

version: "3.1"
services:
  solr1:
    image: solr:latest
    environment:
      - JVM_OPTS=-Xmx12g -Xms12g -XX:MaxPermSize=1024m
    ports:
      - "8983:8983"
    restart: always
    container_name: solr1
    volumes:
     - /root/solr/mycores:/opt/solr/server/solr/mycores
    deploy:
      mode: replicated
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper2:2183 -m 1g'
  solr2:
    image: solr:latest
    ports:
      - "8984:8984"
    restart: always
    container_name: solr2
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  solr3:
    image: solr:latest
    ports:
      - "8985:8985"
    restart: always
    container_name: solr3
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
      - solr2
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  solr4:
    image: solr:latest
    ports:
      - "8986:8986"
    restart: always
    container_name: solr4
    volumes:
     - /root/solr/cores:/opt/solr/server/solr/mycores
    deploy:
      replicas: 2
      resources:
    limits:
      memory: 1g
      restart_policy:
    condition: on-failure
    links:
      - zookeeper1
      - zookeeper2
      - zookeeper3
      - solr1
      - solr2
      - solr3
    command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper3:2183 -m 1g'
  zookeeper1:
    image: jplock/zookeeper:latest
    container_name: zookeeper1
    ports:
      - "2181:2181"
      - "2888:2888"
      - "3888:3888"
    restart: always
  zookeeper2:
    image: jplock/zookeeper:latest
    container_name: zookeeper2
    ports:
      - "2182:2182"
      - "2889:2889"
      - "3889:3889"
    restart: always
  zookeeper3:
    image: jplock/zookeeper:latest
    container_name: zookeeper3
    ports:
      - "2183:2183"
      - "2890:2890"
      - "3890:3890"
    restart: always
1

There are 1 answers

0
Szymon Roziewski On BEST ANSWER

I found a solution. It was needed to add in a docker-compose.yml file a -t parameter and deliver a data directory /opt/solr/server/solr/mycores. The edited line beneath

command: bash -c '/opt/solr/bin/solr start -f -z zookeeper1:2181,zookeeper2:2182,zookeeper2:2183 -m 1g -t /opt/solr/server/solr/mycores'