Docker Installation - EASIEST METHOD

Install Cassandra with Docker

The EASIEST way to run Cassandra - Works on Windows, macOS, and Linux!

๐Ÿณ Docker: The EASIEST Way to Run Cassandra!

โœ… Why Docker is AMAZING for Cassandra

  • ๐Ÿš€ 1 Command Setup: Running in 30 seconds!
  • ๐Ÿ’ป Works Everywhere: Windows, macOS, Linux - same commands
  • ๐Ÿงน Clean Isolation: No system pollution
  • ๐Ÿ”„ Easy Reset: Delete and recreate instantly
  • ๐Ÿ“ฆ Consistent Environment: Same as production
  • ๐ŸŒ Multi-Node Clusters: Test clusters on your laptop!
  • โšก Version Switching: Try different Cassandra versions easily

๐Ÿ’ก Perfect Use Cases

  • โœ… Learning Cassandra: Fastest way to get started
  • โœ… Local Development: No conflicts with your system
  • โœ… Testing: Spin up/down clusters instantly
  • โœ… CI/CD Pipelines: Automated testing
  • โœ… Multi-Node Experiments: Test replication locally
  • โœ… Windows/Mac Users: Get Linux environment easily

๐ŸŽฏ What You'll Learn

  • ๐Ÿณ Install Docker Desktop (any OS)
  • ๐Ÿ“ฆ Run single Cassandra container
  • ๐ŸŽผ Use Docker Compose for easy management
  • ๐ŸŒ Create 3-node Cassandra cluster
  • ๐Ÿ’พ Persist data with volumes
  • โš™๏ธ Essential Docker commands

๐Ÿš€ Let's get Cassandra running with Docker - it's SUPER easy!

๐Ÿณ Step 1: Install Docker Desktop

First, install Docker Desktop for your operating system.

๐ŸชŸ

Windows

  1. Download Docker Desktop from
    docker.com
  2. Run installer (requires WSL 2)
  3. Restart computer
  4. Start Docker Desktop
๐ŸŽ

macOS

  1. Download Docker Desktop from
    docker.com
  2. Drag to Applications
  3. Open Docker Desktop
  4. Wait for startup
๐Ÿง

Linux

# Ubuntu/Debian curl -fsSL https://get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker $USER # Logout and login
โœ“

Verify Docker Installation

# Check Docker version docker --version # Expected output: # Docker version 24.0.x # Test Docker docker run hello-world # If you see "Hello from Docker!" - Success! โœ…

๐Ÿ“ฆ Method 1: Single Container Setup

The quickest way to get Cassandra running!

1

Run Cassandra Container

Literally ONE command!

# Start Cassandra container docker run --name cassandra-node -d -p 9042:9042 cassandra:4.1 # Breakdown: # --name cassandra-node : Name the container # -d : Run in background (detached) # -p 9042:9042 : Expose CQL port # cassandra:4.1 : Use Cassandra 4.1 image

โฑ๏ธ Wait 30-60 seconds for Cassandra to start!

2

Check Container Status

# List running containers docker ps # Expected output: CONTAINER ID IMAGE STATUS PORTS NAMES abc123def456 cassandra:4.1 Up 2 minutes 0.0.0.0:9042->9042/tcp cassandra-node # Check container logs docker logs cassandra-node # Look for: "Starting listening for CQL clients"
3

Connect with cqlsh

# Connect to CQL shell inside container docker exec -it cassandra-node cqlsh # Expected output: Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.1.0 | Cassandra 4.1.x | CQL spec 3.4.6] cqlsh> # Test query SELECT release_version FROM system.local; # Exit exit

That's It! Cassandra is Running! ๐ŸŽ‰

You now have a working Cassandra instance!

  • โœ… Cassandra running on port 9042
  • โœ… Can connect from your host machine
  • โœ… cqlsh available inside container
  • โœ… Ready to learn and experiment!

Important: Data is NOT Persisted!

If you delete the container, all data is lost. To persist data, see the Data Persistence section below.

๐ŸŽผ Method 2: Docker Compose (Recommended)

Better way to manage Cassandra - configuration as code!

1

Create docker-compose.yml

Create a file called docker-compose.yml:

version: '3.8' services: cassandra: image: cassandra:4.1 container_name: cassandra-node ports: - "9042:9042" - "7199:7199" environment: - CASSANDRA_CLUSTER_NAME=DevCluster - CASSANDRA_DC=datacenter1 - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch volumes: - cassandra-data:/var/lib/cassandra healthcheck: test: ["CMD", "cqlsh", "-e", "describe keyspaces"] interval: 30s timeout: 10s retries: 5 volumes: cassandra-data:
2

Start with Docker Compose

# Start Cassandra docker-compose up -d # Output: Creating network "cassandra_default" with the default driver Creating volume "cassandra_cassandra-data" with default driver Creating cassandra-node ... done # Check status docker-compose ps # View logs docker-compose logs -f
3

Connect and Use

# Connect to cqlsh docker-compose exec cassandra cqlsh # Run queries CREATE KEYSPACE dev_ks WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 1 }; USE dev_ks; CREATE TABLE users ( id UUID PRIMARY KEY, name TEXT, email TEXT );

Why Docker Compose is Better

  • โœ… Easy Management: One command to start/stop
  • โœ… Configuration File: Version control your setup
  • โœ… Data Persistence: Volumes configured automatically
  • โœ… Multi-Container: Easy to add more nodes
  • โœ… Environment Variables: Easy customization

๐ŸŒ Method 3: Multi-Node Cluster

Create a 3-node Cassandra cluster on your laptop!

1

Create docker-compose-cluster.yml

version: '3.8' services: cassandra-node1: image: cassandra:4.1 container_name: cassandra-node1 ports: - "9042:9042" environment: - CASSANDRA_CLUSTER_NAME=TestCluster - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch - CASSANDRA_DC=datacenter1 volumes: - cassandra-node1-data:/var/lib/cassandra networks: - cassandra-network cassandra-node2: image: cassandra:4.1 container_name: cassandra-node2 environment: - CASSANDRA_CLUSTER_NAME=TestCluster - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch - CASSANDRA_DC=datacenter1 - CASSANDRA_SEEDS=cassandra-node1 volumes: - cassandra-node2-data:/var/lib/cassandra networks: - cassandra-network depends_on: - cassandra-node1 cassandra-node3: image: cassandra:4.1 container_name: cassandra-node3 environment: - CASSANDRA_CLUSTER_NAME=TestCluster - CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch - CASSANDRA_DC=datacenter1 - CASSANDRA_SEEDS=cassandra-node1 volumes: - cassandra-node3-data:/var/lib/cassandra networks: - cassandra-network depends_on: - cassandra-node1 networks: cassandra-network: driver: bridge volumes: cassandra-node1-data: cassandra-node2-data: cassandra-node3-data:
2

Start the Cluster

# Start all 3 nodes docker-compose -f docker-compose-cluster.yml up -d # Wait 2-3 minutes for nodes to discover each other # Check cluster status docker exec cassandra-node1 nodetool status # Expected output: 3 nodes with UN (Up and Normal) Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns Host ID UN 172.18.0.2 69.91 KiB 16 100.0% ... UN 172.18.0.3 65.87 KiB 16 100.0% ... UN 172.18.0.4 73.45 KiB 16 100.0% ...
3

Test Replication

# Connect to node 1 docker exec -it cassandra-node1 cqlsh # Create keyspace with RF=3 CREATE KEYSPACE test_cluster WITH REPLICATION = { 'class': 'SimpleStrategy', 'replication_factor': 3 }; USE test_cluster; CREATE TABLE products ( id UUID PRIMARY KEY, name TEXT, price DECIMAL ); INSERT INTO products (id, name, price) VALUES (uuid(), 'Laptop', 999.99); exit # Connect to node 2 - data is replicated! docker exec -it cassandra-node2 cqlsh USE test_cluster; SELECT * FROM products; # You'll see the data! โœ…

You Just Created a Real Cassandra Cluster! ๐ŸŽ‰

This is amazing for learning:

  • โœ… Test replication across nodes
  • โœ… Practice with multi-datacenter concepts
  • โœ… Simulate node failures
  • โœ… Learn cluster operations
  • โœ… All on your laptop!

๐Ÿ’พ Data Persistence with Volumes

Make sure your data survives container restarts!

Why Volumes Matter

Without volumes: Deleting container = losing all data

With volumes: Data persists even after container deletion

1

Single Container with Volume

# Create named volume docker volume create cassandra-data # Run container with volume docker run --name cassandra-node -d \ -p 9042:9042 \ -v cassandra-data:/var/lib/cassandra \ cassandra:4.1 # Now data persists! # You can stop/start/recreate container without losing data
2

Manage Volumes

# List volumes docker volume ls # Inspect volume docker volume inspect cassandra-data # Remove volume (BE CAREFUL - deletes data!) docker volume rm cassandra-data # Remove all unused volumes docker volume prune
3

Backup Data from Volume

# Create backup docker run --rm \ -v cassandra-data:/data \ -v $(pwd):/backup \ busybox tar czf /backup/cassandra-backup.tar.gz /data # This creates cassandra-backup.tar.gz in current directory # Restore from backup docker run --rm \ -v cassandra-data:/data \ -v $(pwd):/backup \ busybox tar xzf /backup/cassandra-backup.tar.gz -C /

โš™๏ธ Essential Docker Commands

Cheat sheet for managing Cassandra containers!

๐Ÿš€ Starting & Stopping

# Start container docker start cassandra-node # Stop container docker stop cassandra-node # Restart container docker restart cassandra-node # With Docker Compose docker-compose up -d # Start docker-compose stop # Stop docker-compose restart # Restart docker-compose down # Stop and remove

๐Ÿ“Š Monitoring

# View logs docker logs cassandra-node docker logs -f cassandra-node # Follow logs # Check resources docker stats cassandra-node # Node status docker exec cassandra-node nodetool status docker exec cassandra-node nodetool info # List containers docker ps # Running docker ps -a # All

๐Ÿ’ป Executing Commands

# Connect to cqlsh docker exec -it cassandra-node cqlsh # Run bash inside container docker exec -it cassandra-node bash # Run nodetool commands docker exec cassandra-node nodetool status docker exec cassandra-node nodetool describecluster docker exec cassandra-node nodetool ring

๐Ÿ—‘๏ธ Cleanup

# Remove container docker rm cassandra-node docker rm -f cassandra-node # Force remove running # Remove image docker rmi cassandra:4.1 # Clean up everything docker-compose down -v # Remove volumes too # Remove all stopped containers docker container prune # Remove all unused images docker image prune -a

๐Ÿ” Debugging

# Inspect container docker inspect cassandra-node # View resource usage docker stats # Check logs for errors docker logs cassandra-node | grep ERROR # Test network connectivity docker exec cassandra-node ping google.com

๐Ÿ”ง Common Issues & Solutions

Fix common Docker + Cassandra problems!

โŒ Container starts but immediately stops

Problem: Not enough memory or port conflict

Solutions:

  1. Check Docker Desktop has at least 4GB RAM allocated
  2. Check if port 9042 is already in use: lsof -i :9042
  3. View logs: docker logs cassandra-node

โŒ "Cannot connect to CQL"

Problem: Cassandra not fully started

Solution:

# Wait for "Starting listening for CQL clients" docker logs -f cassandra-node # Usually takes 30-60 seconds # Be patient! โฑ๏ธ

โŒ Nodes not joining cluster

Problem: Network or timing issue

Solutions:

  1. Start nodes one at a time with 30s delay between each
  2. Check network: docker network inspect cassandra-network
  3. Verify CASSANDRA_SEEDS is set correctly
  4. Start fresh: docker-compose down -v && docker-compose up -d

โŒ "Port is already allocated"

Problem: Another process using port 9042

Solution:

# Find process using port # macOS/Linux: lsof -i :9042 # Windows: netstat -ano | findstr 9042 # Kill it or change Docker port: docker run -p 9043:9042 ...

โŒ Docker Desktop not starting (Windows)

Problem: WSL 2 or Hyper-V issues

Solutions:

  1. Enable WSL 2: wsl --install in PowerShell (Admin)
  2. Update WSL: wsl --update
  3. Enable Hyper-V in Windows Features
  4. Restart computer

โŒ Very slow performance

Problem: Docker resource limits

Solution:

Increase Docker Desktop resources:

  • Memory: At least 4GB (8GB recommended)
  • CPU: At least 2 cores (4 recommended)
  • Disk: At least 20GB

Settings โ†’ Resources โ†’ Adjust values

Nuclear Option: Start Fresh

If nothing works:

# Stop and remove everything docker-compose down -v docker rm -f $(docker ps -aq) docker volume prune -f # Start from scratch docker-compose up -d # Usually fixes most issues!

๐ŸŽ‰ Docker + Cassandra = Perfect Match!

Congratulations! You now know how to run Cassandra with Docker!

๐Ÿš€ What You Learned:

  • ๐Ÿณ Single container: Quick setup in 1 command
  • ๐ŸŽผ Docker Compose: Better management with config files
  • ๐ŸŒ Multi-node cluster: 3-node cluster on your laptop!
  • ๐Ÿ’พ Data persistence: Volumes to keep your data safe
  • โš™๏ธ Essential commands: Manage, monitor, and debug

๐Ÿ’ก Quick Reference:

# Quick start (single node) docker run --name cassandra -d -p 9042:9042 cassandra:4.1 # Connect to cqlsh docker exec -it cassandra cqlsh # Stop docker stop cassandra # Start again docker start cassandra # Remove (loses data) docker rm -f cassandra

๐Ÿณ Docker makes learning Cassandra SO much easier!

Advertisement

Responsive Ad