I was wondering if someone has tried to build a cassandra docker image with default keyspace, I've tried to do it on BUILD time but it doesn't work because cassandra is not running in that phase. It was something similar to this:
FROM cassandra:2.0
COPY ../somewhere/keyspace_definition.txt /src/keyspace_definition.txt
RUN /usr/bin/cqlsh -f /src/keyspace_definition.txt
My new approach will be to do it from the entrypoint script, but, I wanted to now if someone else has a better idea.
Happy shipping :D
Tackled this issue today. Build image, which overwrites default Cassandra
docker-entrypoint.sh
with one modified, appended, right beforeexec "$@"
Put the desired *.cql in image in
docker-entrypoint-initdb.d/
.Image will start, boot up the cassandra, and retries inserting to the database unless it succeeds. Just make sure your scripts are
IF NOT EXISTS
otherwise the script will run indefinitely.Base on answers from @jan-oudrincky and @alexander-morozov, I build a new docker image which has a wrapper of original
docker-entrypoint.sh
to create keyspace when environment variableCASSANDRA_KEYSPACE
is set. It will be useful in dev/test environment.It doesn't modify
docker-entrypoint.sh
so even if cassandra base image has any modification you just need a rebuild.Dockerfile
entrypoint-wrap.sh
I find it interesting that nobody responded to this yet. You can follow that they did with MySQL running in a container I supposed.
Refer to this link: http://www.luiselizondo.net/a-tutorial-on-how-to-use-mysql-with-docker/
Any script you put in that directory will be executed through the /entrypoint.sh script. Looks like Cassandra's entrypoint.sh script does not support this yet. However! It could!
I'm using a Spring-Boot docker container to access my cassandra container. Everything is orchestrated by a dockr-compose. this tutorial in combination with the following code worked for me.
I used this decisions. I deleted last line from file docker-entrypoint.sh and inserted in the end those lines:
Then it's necessary to rebuild docker image.