Testing Cassandra Replication factors with different consistency levels
224
This repository contains a Docker image of Apache Cassandra designed for easy local development and learning.
Built from a running container and fully compatible with Docker Desktop on Windows, Linux, and macOS.
Connect to Cassandra using CQLSH docker exec -it cassandra-node1 cqlsh
๐งช Example: Create Keyspace and Table Create Keyspace CREATE KEYSPACE demo WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2};
Create Table CREATE TABLE demo.users ( id UUID PRIMARY KEY, name text, age int );
Insert Sample Data INSERT INTO demo.users (id, name, age) VALUES (uuid(), 'Alice', 25); INSERT INTO demo.users (id, name, age) VALUES (uuid(), 'Bob', 30);
๐ฌ Read Data SELECT * FROM demo.users;
๐ Troubleshooting Cassandra does not start?
Try increasing WSL2 memory using .wslconfig:
[wsl2] memory=6GB processors=4 swap=1GB
CQLSH connection refused?
Wait 20โ40 seconds โ Cassandra takes time to bootstrap.
docker pull saradindusamal10/cassandra-test:node1_v1
2. Run a Single Cassandra Node
docker run -d --name cassandra-node1 \
-p 9042:9042 \
--network cassandra-net \
-e CASSANDRA_CLUSTER_NAME="TestCluster" \
-e CASSANDRA_SEEDS="cassandra-node1" \
-e CASSANDRA_LISTEN_ADDRESS=cassandra-node1 \
-e CASSANDRA_BROADCAST_ADDRESS=cassandra-node1 \
-e CASSANDRA_ENDPOINT_SNITCH=SimpleSnitch \
saradindusamal10/cassandra-test:node1_v1
Optional: Create Docker Network (if needed)
docker network create cassandra-net
Multi-Node Cassandra Cluster Example
1. Start Node 1 (Seed Node)
docker run -d --name cassandra-node1 \
--network cassandra-net \
-p 9042:9042 \
-e CASSANDRA_CLUSTER_NAME="TestCluster" \
-e CASSANDRA_SEEDS="cassandra-node1" \
-e CASSANDRA_LISTEN_ADDRESS=cassandra-node1 \
-e CASSANDRA_BROADCAST_ADDRESS=cassandra-node1 \
saradindusamal10/cassandra-test:node1_v1
2. Start Node 2
docker run -d --name cassandra-node2 \
--network cassandra-net \
-e CASSANDRA_CLUSTER_NAME="TestCluster" \
-e CASSANDRA_SEEDS="cassandra-node1" \
-e CASSANDRA_LISTEN_ADDRESS=cassandra-node2 \
-e CASSANDRA_BROADCAST_ADDRESS=cassandra-node2 \
saradindusamal10/cassandra-test:node1_v2
Verify Cluster Status
docker exec -it cassandra-node1 nodetool status
Expected:
Both nodes should be in UN state (Up/Normal)
Connect to Cassandra using CQLSH
docker exec -it cassandra-node1 cqlsh
๐งช Example: Create Keyspace and Table
Create Keyspace
CREATE KEYSPACE testks
WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 2};
Create Table
CREATE TABLE testks.users (
id UUID PRIMARY KEY,
name text,
age int
);
Insert Sample Data
INSERT INTO testks.users (id, name, age) VALUES (uuid(), 'Alice', 25);
INSERT INTO testks.users (id, name, age) VALUES (uuid(), 'Bob', 30);
๐ฌ Read Data
SELECT * FROM testks.users;
๐ Troubleshooting
Cassandra does not start?
Try increasing WSL2 memory using .wslconfig:
[wsl2]
memory=6GB
processors=4
swap=1GB
CQLSH connection refused?
Wait 20โ40 seconds โ Cassandra takes time to bootstrap.
Content type
Image
Digest
sha256:8d42ddbdfโฆ
Size
150.9 MB
Last updated
10 months ago
docker pull saradindusamal10/cassandra-test:node1_v1