Reputation: 9624
This is my docker-compose.yml
-
version: "3"
services:
solr:
build: ./services/solr
ports:
- "8983:8983"
container_name: solr
volumes:
- ./services/solr/config/my_collection:/config/my_collection
solr_data_loader:
build: ./services/solr_data_loader
container_name: solr_data_loader
volumes:
- ./services/solr_data_loader/data:/opt/data
restart: always
depends_on:
- solr
As you can see, I have a service named solr
that uses the official solr
image from docker hub. Along with that, I have another service named solr_data_loader
that copies data from local into Solr using a bash script by running a cURL command to the solr
UI with this REST endpoint - http://solr:8983/solr/my_collection/update/csv?commit=true"
.
My question is - is the way my solr_data_loader
set up considered as good practice with respect to how docker containers are supposed to work? Of course, I could just run a separate bash script to do this data transfer job, but this seems like a lot cleaner approach to me to have a separate container that goes down after doing the job.
Upvotes: 0
Views: 91
Reputation: 81
I think this is perfectly fine. In some scenarios, it is difficult or simply not possible to run shell commands (i.e. Kubernetes, Docker Swarm), so starting a separate container for configuration and migration tasks is a common practice.
You may even consider to do this without an HTTP endpoint, but start the migration on container start and let the container exit after the migration completes depending on your deployment infrastructure.
Another aspect is testing. You can easily set up a docker-compose with your database, the migration container and check if the container works as intended. Sure, this would be possible with a shell script too, but having only one type of deployment artifact (docker image) is very elegant too.
Upvotes: 1