We recently tried to solve a similar problem in KillrVideo , the help application for Cassandra. We use Docker Compose to deploy the environment needed for an application that includes a DataStax Enterprise (i.e. Cassandra) node. We wanted node to do some reboot on the first start of the installation of the CQL schema (using cqlsh to run the statements in the .cql file just like you are trying to do). Basically the approach we took was to write a shell script for our Docker entry point, which:
- Usually starts node, but in the background.
- Expects port 9042 is available (here clients connect to the execution of CQL instructions). A.
- Uses
cqlsh -f to run some CQL statements and initialize the schema. - Stops a node that is running in the background.
- The usual entry point continues for our Docker image, which usually launches node (in the foreground, as expected, Docker).
We simply use the existence of the file to indicate whether the node has already been loaded, and check to determine at startup whether we need to make this logic higher or just start it normally. You can see the results in the killrvideo-dse-docker repository on GitHub .
There is one caveat to this approach. This worked for us because in our help application we only expand one node (i.e. we do not create a cluster with more than one node). If you are using multiple nodes, you will probably want to make sure that only one of the nodes is loading to create the scheme, since several clients changing the scheme at the same time can cause some problems with your cluster, (This is a known problem and hopefully will fixed at some point.)
source share