1. Introduction

In this short tutorial, we'll go through creating a Cassandra cluster composed of three nodes using Docker Compose.

Running a Cassandra cluster in Docker involves setting up multiple Docker containers, one for each node in the cluster. If you don't want to use Docker Compose, you can create the cluster using just Docker by executing a couple of Docker commands.

Docker Compose is a handy tool that simplifies this process by defining the complete cluster's configuration in a YAML file.

2. Configuration

Here are the steps to run a Cassandra cluster using Docker Compose:

  1. Make sure you have Docker and Docker Compose installed on your system. You can download and install them from the official Docker website if you haven't already.

  2. Create a Docker Compose YAML file named docker-compose.yml in a directory of your choice. This file defines the configuration for your future Cassandra cluster. Here's a sample configuration for a simple 3-node cluster:

    version: '3'
    
    services:
      cassandra1:
        image: cassandra:latest
        container_name: cassandra1
        ports:
          - "9042:9042"
        environment:
          - CASSANDRA_SEEDS=cassandra1,cassandra2,cassandra3
        networks:
          - cassandra-network
      cassandra2:
        image: cassandra:latest
        container_name: cassandra2
        environment:
          - CASSANDRA_SEEDS=cassandra1,cassandra2,cassandra3
        networks:
          - cassandra-network
      cassandra3:
        image: cassandra:latest
        container_name: cassandra3
        environment:
          - CASSANDRA_SEEDS=cassandra1,cassandra2,cassandra3
        networks:
          - cassandra-network
    
    networks:
      cassandra-network:
        driver: bridge​
  3. Open a terminal or command prompt, navigate to the directory containing the docker-compose.yml file, and run the following command:
    docker-compose up​ -d

    This command will start three Cassandra containers named cassandra1, cassandra2, and cassandra3, each one running on a separate Docker container.
    The -d flag runs the containers in the background.

  4. To verify that everything is ok and the cluster is up and running, you can check the container logs or use a tool like nodetool to connect to one of the containers and then inspect the cluster status:

    docker exec -it cassandra1 nodetool status

    This command connects to the cassandra1 container and runs the nodetool status command to display the cluster status.

3. Conclusion

Congratulations, now you have a simple Cassandra cluster running in Docker. In the case of a production environment, you may need to customize cluster configuration based on your specific requirements and take care of data persistence using Docker volumes.