This gist shows you how to easily create a cassandra image with initial keyspace and values populated.
It is very generic: the entrypoint.sh is able to execute any cql file located in /docker-entrypoint-initdb.d/,
a bit like what you do to initialize a MySQL container.
You can add any *.sh or *.cql scripts inside /docker-entrypoint-initdb.d, but note that:
*.shfiles will be executed BEFORE launching cassandra*.cqlfiles will be executed (withcqlsh -f) AFTER cassandra started
Files are executed in name order (ls * | sort)
- download the
Dockerfileandentrypoint.sh - edit the
Dockerfilein order to copy your init scripts inside/docker-entrypoint-initdb.d/ - build the image:
docker build -t my-cassandra-image . - run the image:
docker run --rm -p 9042:9042 --name cassandra-container -d my-cassandra-image
Note that the scripts in /docker-entrypoint.sh will only be called on startup. If you decide to persist the data using a volume,
this will work all right: the scripts won't be executed when you boot your container a second time. By using a volumne, I mean, e.g.:
docker run --rm -d \
-p 9042:9042 \
-v $PWD/data:/var/lib/cassandra \
--name cassandra-container \
my-cassandra-image
I checked in Cassandra 5.0
"docker-entrypoint.sh" file has been moved and its path is: "/usr/local/bin/docker-entrypoint.sh".
If you comment the line 54 in "entrypoint.sh" file, you cannot access to Cassandra from other docker containers