How to create a Dockerfile for cassandra (or any database) that includes a schema?

Ok I had this issue and someone advised me some strategy to deal with:

  1. Start from an existing Cassandra Dockerfile, the official one for example
  2. Remove the ENTRYPOINT stuff
  3. Copy the schema (.cql) file and data (.csv) into the image and put it somewhere, /opt/data for example
  4. create a shell script that will be used as the last command to start Cassandra

    a. start cassandra with $CASSANDRA_HOME/bin/cassandra

    b. IF there is a $CASSANDRA_HOME/data/data/your_keyspace-xxxx folder and it's not empty, do nothing more

    c. Else

    1. sleep some time to allow the server to listen on port 9042
    2. when port 9042 is listening, execute the .cql script to load csv files
    

I found this procedure rather cumbersome but there seems to be no other way around. For Cassandra hands-on lab, I found it easier to create a VM image using Vagrant and Ansible.