Setting up Apache Cassandra on Docker Container


Follow the below commands to set up Apache Cassandra on Docker Container

Step 1: Pull Cassandra Docker Image

sudo docker pull cassandra:latest

Step 2: Run Cassandra Docker Image as Docker Container

sudo docker run -d --name cassandra-node -p 9042:9042 cassandra

Step 3: Login to cassandra-node(Docker Container) on bash mode

sudo docker exec -it cassandra-node bash

Step 4: Open Cassandra SQL CLI

cqlsh

Step 5: Create Keyspace

CREATE KEYSPACE test_ks WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};

Step 6: Connect to Keyspace using "use" command

USE test_ks;

Step 7: Create Cassandra Table

CREATE TABLE test_ks.user_dtl (user_id int PRIMARY KEY, user_name text, city text);

Step 8: Insert data into Cassandra Table

INSERT INTO user_dtl (user_id, user_name, city) VALUES(1, 'Arun', 'Chennai');
INSERT INTO user_dtl (user_id, user_name, city) VALUES(2, 'Ram', 'Bangalore');
INSERT INTO user_dtl (user_id, user_name, city) VALUES(3, 'Shiva', 'Hyderabad');

Step 9: Select data from Cassandra Table

select * from user_dtl;

Step 10: Select limited rows from Cassandra Table

select * from user_dtl LIMIT 2;

Post a Comment

0 Comments