Seeding Cassandra Using Docker

Posted on December 06, 2015 in docker, docker-compose, cassandra

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.

Docker Compose

We're going to build a simple docker-compose.yml file that defines one instance.

# Cassandra Database
  build: .
    - "9042"


Our 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/

The .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]

Thomas Lackemann :)


Tom is the founder of Astral TableTop. He's a homebrewer, hiker, and has an about page. Follow @tlackemann on Twitter for more discussions like this.