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:
- starts node in background.
- waits until port 9042 available (this clients connect run cql statements).
- uses
cqlsh -f
run cql statements , init schema. - stops node that's running in background.
- 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
Post a Comment