Warm tip: This article is reproduced from stackoverflow.com, please click
docker docker-compose solr yaml

Copy files inside of docker container before volumes are created (Solr docker image with custom conf

发布于 2020-04-21 11:02:47

I need to create docker container with Solr that has custom configuration created. In order to create that config when installed not in docker container I need to do the following:

cp -r /opt/solr/server/solr/configsets/basic_configs /opt/solr/server/solr/configsets/myconf

Then I have to copy my custom schema.xml to that location:

cp conf/schema.xml solr/server/solr/configsets/myconf/conf

And then remove managed schema:

rm /opt/solr/server/solr/configsets/nutch/conf/managed-schema

I have this docker-compose.yml that I need to modify to do the same as commands above:

version: '3.3'
services:
  solr:
    image: "solr:7.3.1"
    ports:
     - "8983:8983"
    volumes:
      - ./solr/conf/solr-mapping.xml:/opt/solr/conf/schema.xml
    entrypoint:
      - docker-entrypoint.sh
      - solr-precreate
      - mycore

schema.xml can go to valumes part, but I don't really understand where should I place this first cp and rm commands.

Thanks!

Questioner
kodlan
Viewed
141
shinee 2020-02-14 13:28

You can add your commands to your docker compose file ( https://docs.docker.com/compose/compose-file/#command)

version: '3.3'
services:
  solr:
  image: "solr:7.3.1"
  ports:
    - "8983:8983"
  volumes:
      - ./solr/conf/solr-mapping.xml:/opt/solr/conf/schema.xml

  command: 'bash -e -c "precreate-core mycore; cp /opt/solr/conf/schema.xml /opt/solr/server/solr/mycores/mycore/conf/schema.xml; cp /opt/solr/conf/solrconfig.xml /opt/solr/server/solr/mycores/mycore/conf/solrconfig.xml; rm /opt/solr/server/solr/mycores/mycore/conf/managed-schema; solr-foreground;"'

it works for me