Getting up and running with Cassandra using Docker is extremely simple. Getting data into Cassandra via
cqlsh however, is a little less intuitive. In this tutorial, we'll look at a simple application that utilizes
docker-compose to start a Cassandra instance and then learn how to seed data into that instance.
I assume you have some knowledge of what Docker and Cassandra are and how to use each one.
You can view the example source code on GitHub.
We're going to build a simple
docker-compose.yml file that defines one instance.
# Cassandra Database cassandra: build: . expose: - "9042"
Dockerfile simply extends cassandra from Docker and copies a migration
.cql file up to the container.
FROM cassandra RUN mkdir /data COPY data/initial-seed.cql /data/
.cql file should contain any CQL commands needed to setup your initial Cassandra instance.
Build and start your instance.
docker-compose build docker-compose up
Then seed your data.
docker run -it --link my_cassandra_container_name:cassandra --rm my_cassandra_container_name sh -c 'exec cqlsh "$CASSANDRA_PORT_9042_TCP_ADDR" -f /data/initial-seed.cql'
Feel free to play with the configuration and link some of your existing images to your newly seeded Cassandra instance.
Feedback, questions, comments? Email me at tommylackemann [at] gmail.com