Skip to content

Instantly share code, notes, and snippets.

@monkut
Last active May 14, 2018 21:05
Show Gist options
  • Save monkut/f5c8cd13721bf954e3439609dda50fb6 to your computer and use it in GitHub Desktop.
Save monkut/f5c8cd13721bf954e3439609dda50fb6 to your computer and use it in GitHub Desktop.
Using spotify cassandra docker image

https://github.com/spotify/docker-cassandra

getting and starting single-node cassandra

This describes the method to obtain and run the spotify/cassandra single-node instance on ubuntu 16.04 where docker is already installed.

  1. Obtain image
sudo docker pull spotify/cassandra
  1. Start image
# start container as *daemon*, mapping ports to local ports for external connections
docker run -d -p 9042:9042 -p 9160:9160 --name cassandra spotify/cassandra
  1. confirm cassandra is running:
# enter image
sudo docker exec -it cassandra /bin/bash

# connect via cqlsh
root@8d051e6ee21d:/# cqlsh
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.10 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>  
cqlsh> DESCRIBE keyspaces

system system_traces  

# quit/exit
cqlsh> exit
exit

Confirm external connection

On local machine

  1. Install cassandra connector:
python3 -m pip install cassandra-driver
  1. Open python console, connect to server, and confirm session & query features:
>>> from cassandra.cluster import Cluster
>>>
>>> cluster = Cluster([IP_ADDRESS])
>>> session = cluster.connect()
>>>
>>> for keyspace in session.execute('SELECT * FROM system.schema_keyspaces'):
...     print(keyspace)
...
Row(keyspace_name='system', durable_writes=True, strategy_class='org.apache.cassandra.locator.LocalStrategy', strategy_options='{}')
Row(keyspace_name='system_traces', durable_writes=True, strategy_class='org.apache.cassandra.locator.SimpleStrategy', strategy_options='{"replication_factor":"2"}')
>>> exit()
  1. Start exploring!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment