Illustration Image

Cassandra.Link

The best knowledge base on Apache Cassandra®

Helping platform leaders, architects, engineers, and operators build scalable real time data platforms.

10/31/2017

Reading time:2 min

Docker-Cassandra

by John Doe

This repository contains a set of scripts and configuration files to run a Cassandra clusterfrom Docker containers. The current version of this repository isconfigured to create a Cassandra 1.2 or 2.0 image and cluster.Example:Cassandra nodes are created with their own IP address and configured hostname:$ ./start-cluster.sh 2.0.3 3Starting node 1Starting node 2Starting node 3$ ./client.sh 2.0.3 nodetool -h cass1 statusDatacenter: datacenter1=======================Status=Up/Down|/ State=Normal/Leaving/Joining/Moving-- Address Load Tokens Owns Host ID RackUN 192.168.100.3 40.84 KB 256 34.9% 9d4a223f-e80e-4b50-b379-0705b1c8971d rack1UN 192.168.100.1 38.93 KB 256 33.7% 5128dcb0-14d0-4d17-9b53-acc8f9a0844b rack1UN 192.168.100.2 30.92 KB 256 31.4% 8e6faaba-601f-4812-a33b-05ceaecf1159 rack1Note that the nodes might take about 30 seconds to show up as they join the Cassandra ring.The shell scripts all assume that you have sudo privilege.Getting started1. Check out this repository$ git clone https://github.com/nicolasff/docker-cassandra.git$ cd docker-cassandra2. Install pipeworkMake sure that the bundled script pipework is in your path. You can install it with:$ sudo cp install/bin/pipework /usr/bin/The latest version is on GitHub at https://github.com/jpetazzo/pipework.3. Create a Docker image for CassandraTo create a Cassandra 2.0.3 image and tag it, run:$ make image VERSION=2.0.3You should then see it appear in your list of Docker images:$ sudo docker imagesREPOSITORY TAG ID CREATED SIZEcassandra 2.0.3 b9ba84a33bb5 About a minute ago 12.29 kB (virtual 404.7 MB)$ ./list-images.sh2.0.34. Start a clusterRun ./start-cluster.sh 2.0.3 3 to create a cluster of 3 nodes running Cassandra 2.0.3. They are given an IP address and name each, from cass1 (192.168.100.1) to cass3 (192.168.100.3).Run sudo docker ps to list your Cassandra nodes:$ sudo docker psID IMAGE COMMAND CREATED STATUS PORTS99d67692f535 cassandra:2.0.3 /usr/bin/start-cassa 10 minutes ago Up 10 minutes 49332->9160 fe7e2b13cb9e cassandra:2.0.3 /usr/bin/start-cassa 10 minutes ago Up 10 minutes 49331->9160 f21da380b00c cassandra:2.0.3 /usr/bin/start-cassa 10 minutes ago Up 10 minutes 49330->9160 5. Connect to your clusterCassandra nodes expose port 9160 for Thrift. Use sudo docker port <container-id> 9160 or sudo docker ps to find the local port it is mapped to.client.sh creates a docker container with access to the Cassandra cluster network (192.168.100.0/24). The first client is given the name cass254with IP 192.168.100.254, the next one cass253, etc. Names are reused when client containers are stopped.client.sh runs any command that is passed to it, e.g. nodetool, cassandra-cli, cqlsh... You can also open a shell with ./client.sh 2.0.3 bash.6. Terminate your cluster$ ./stop-cluster.sh 2.0.3Killing and removing containers 99d67692f535 fe7e2b13cb9e f21da380b00c$ sudo docker psID IMAGE COMMAND CREATED STATUS PORTSLicensing and contributionsThis set of scripts and configuration files is released under the Apache 2.0 License.pipework is Copyright 2013 Jérôme Petazzoni and distributed under the Apache 2.0 license.Contributions and suggestions welcome on GitHub or on Twitter.

Illustration Image

This repository contains a set of scripts and configuration files to run a Cassandra cluster from Docker containers. The current version of this repository is configured to create a Cassandra 1.2 or 2.0 image and cluster.

Example:

Sample session

Cassandra nodes are created with their own IP address and configured hostname:

$ ./start-cluster.sh 2.0.3 3
Starting node 1
Starting node 2
Starting node 3
$ ./client.sh 2.0.3 nodetool -h cass1 status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
--  Address        Load       Tokens  Owns   Host ID                               Rack
UN  192.168.100.3  40.84 KB   256     34.9%  9d4a223f-e80e-4b50-b379-0705b1c8971d  rack1
UN  192.168.100.1  38.93 KB   256     33.7%  5128dcb0-14d0-4d17-9b53-acc8f9a0844b  rack1
UN  192.168.100.2  30.92 KB   256     31.4%  8e6faaba-601f-4812-a33b-05ceaecf1159  rack1

Note that the nodes might take about 30 seconds to show up as they join the Cassandra ring.

The shell scripts all assume that you have sudo privilege.

Getting started

1. Check out this repository

$ git clone https://github.com/nicolasff/docker-cassandra.git
$ cd docker-cassandra

2. Install pipework

Make sure that the bundled script pipework is in your path. You can install it with:

$ sudo cp install/bin/pipework /usr/bin/

The latest version is on GitHub at https://github.com/jpetazzo/pipework.

3. Create a Docker image for Cassandra

To create a Cassandra 2.0.3 image and tag it, run:

$ make image VERSION=2.0.3

You should then see it appear in your list of Docker images:

$ sudo docker images
REPOSITORY          TAG                 ID                  CREATED              SIZE
cassandra           2.0.3              b9ba84a33bb5        About a minute ago   12.29 kB (virtual 404.7 MB)
$ ./list-images.sh
2.0.3

4. Start a cluster

Run ./start-cluster.sh 2.0.3 3 to create a cluster of 3 nodes running Cassandra 2.0.3. They are given an IP address and name each, from cass1 (192.168.100.1) to cass3 (192.168.100.3).

Run sudo docker ps to list your Cassandra nodes:

$ sudo docker ps
ID                  IMAGE               COMMAND                CREATED             STATUS              PORTS
99d67692f535        cassandra:2.0.3    /usr/bin/start-cassa   10 minutes ago      Up 10 minutes       49332->9160         
fe7e2b13cb9e        cassandra:2.0.3    /usr/bin/start-cassa   10 minutes ago      Up 10 minutes       49331->9160         
f21da380b00c        cassandra:2.0.3    /usr/bin/start-cassa   10 minutes ago      Up 10 minutes       49330->9160  

5. Connect to your cluster

Cassandra nodes expose port 9160 for Thrift. Use sudo docker port <container-id> 9160 or sudo docker ps to find the local port it is mapped to.

client.sh creates a docker container with access to the Cassandra cluster network (192.168.100.0/24). The first client is given the name cass254 with IP 192.168.100.254, the next one cass253, etc. Names are reused when client containers are stopped.

client.sh runs any command that is passed to it, e.g. nodetool, cassandra-cli, cqlsh... You can also open a shell with ./client.sh 2.0.3 bash.

6. Terminate your cluster

$ ./stop-cluster.sh 2.0.3
Killing and removing containers 99d67692f535 fe7e2b13cb9e f21da380b00c
$ sudo docker ps
ID                  IMAGE               COMMAND             CREATED             STATUS              PORTS

Licensing and contributions

This set of scripts and configuration files is released under the Apache 2.0 License. pipework is Copyright 2013 Jérôme Petazzoni and distributed under the Apache 2.0 license.

Contributions and suggestions welcome on GitHub or on Twitter.

Related Articles

python
java
cassandra

Vald

John Doe

2/11/2024

Checkout Planet Cassandra

Claim Your Free Planet Cassandra Contributor T-shirt!

Make your contribution and score a FREE Planet Cassandra Contributor T-Shirt! 
We value our incredible Cassandra community, and we want to express our gratitude by sending an exclusive Planet Cassandra Contributor T-Shirt you can wear with pride.

Join Our Newsletter!

Sign up below to receive email updates and see what's going on with our company

Explore Related Topics

AllKafkaSparkScyllaSStableKubernetesApiGithubGraphQl

Explore Further

github