Install Cassandra Inside Docker Container in Linux

Install Cassandra Inside Docker Container in Linux

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.

Prepare environment

Make sure you have installed Docker in your system. If you are using Ubuntu, installation instructions can be found in the post.

Install Cassandra

  • 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:

PortDescription
7000Used for inter-node cluster communication.
7001Used for SSL inter-node cluster communication.
7199Used for JMX monitoring of the Cassandra node.
9042Client port that used to connect to Cassandra and perform operations.
9160Cassandra Thrift client port.

Ports can be changed with -p option.

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.

Testing Cassandra

Run the following command to open the Cassandra client and display a list of all keyspaces:

docker exec -it cassandra cqlsh -e "DESCRIBE keyspaces"

Output:

system       system_distributed  system_traces  system_virtual_schema
system_auth  system_schema       system_views

Uninstall Cassandra

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

Leave a Comment

Cancel reply

Your email address will not be published.