Cassandra is a distributed NoSQL database that is designed for high reliability, availability and scalability to handle large amounts of structured and unstructured data across multiple servers.
This tutorial explains how to install Cassandra inside a Docker container in the Linux. Commands have been tested on Ubuntu.
Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.
- Host network
Run the following command to create a container for Cassandra that uses host network:
docker run -d --name=cassandra --restart=always --network=host \ -v /opt/cassandra/data:/var/lib/cassandra \ cassandra
- User-defined bridge network
User-defined bridge network can be used for listening on different port. By default, Cassandra service is listening on the following ports:
|7000||Used for inter-node cluster communication.|
|7001||Used for SSL inter-node cluster communication.|
|7199||Used for JMX monitoring of the Cassandra node.|
|9042||Client port that used to connect to Cassandra and perform operations.|
|9160||Cassandra Thrift client port.|
Ports can be changed with
docker network create app-net
docker run -d --name=cassandra --restart=always --network=app-net \ -p 8080:7000 -p 8081:7001 -p 8082:7199 -p 8083:9042 -p 8084:9160 \ -v /opt/cassandra/data:/var/lib/cassandra \ cassandra
Note: It might take a while before initialization is finished and the Docker container starts to respond to requests.
Run the following command to open the Cassandra client and display a list of all keyspaces:
docker exec -it cassandra cqlsh -e "DESCRIBE keyspaces"
system system_distributed system_traces system_virtual_schema system_auth system_schema system_views
To completely remove Cassandra, remove its container:
docker rm --force cassandra
Remove Cassandra image:
docker rmi cassandra
You can also remove Cassandra data:
sudo rm -rf /opt/cassandra
If a user-defined bridge network was created, you can delete it as follows:
docker network rm app-net