Init script for Cassandra with docker-compose -


i create keyspaces , column-families @ start of cassandra container.

i tried following in docker-compose.yml file:

# shortened clarity cassandra:     hostname: my-cassandra     image: my/cassandra:latest     command: "cqlsh -f init-database.cql" 

the image my/cassandra:latest contains init-database.cql in /. not seem work.

is there way make happen ?

we tried solve similar problem in killrvideo, reference application cassandra. using docker compose spin environment needed application includes datastax enterprise (i.e. cassandra) node. wanted node bootstrapping first time started install cql schema (using cqlsh run statements in .cql file you're trying do). approach took write shell script our docker entrypoint that:

  1. starts node in background.
  2. waits until port 9042 available (this clients connect run cql statements).
  3. uses cqlsh -f run cql statements , init schema.
  4. stops node that's running in background.
  5. continues on usual entrypoint our docker image starts node (in foreground docker expects).

we use existence of file indicate whether node has been bootstrapped , check on startup determine whether need logic above or can start normally. can see results in killrvideo-dse-docker repository on github.

there 1 caveat approach. worked great because in our reference application, we're spinning single node (i.e. aren't creating cluster more 1 node). if you're running multiple nodes, you'll want make sure one of nodes bootstrapping create schema because multiple clients modifying schema simultaneously can cause issues cluster. (this is known issue , fixed @ point.)


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -