Running a Apache Cassandra Cluster with Docker-Swarm is quite easy using the official Docker Image. Docker-Swarm allows you to setup several docker worker nodes running on different hardware or virtual servers. Take a look at my example docker-compose.yml file:
version: "3.2" networks: cluster_net: external: name: cassandra-net services: ################################################################ # The Casandra cluster # - cassandra-node1 ################################################################ cassandra-001: image: cassandra:3.11 environment: CASSANDRA_BROADCAST_ADDRESS: "cassandra-001" deploy: restart_policy: condition: on-failure max_attempts: 3 window: 120s placement: constraints: - node.hostname == node-001 volumes: - /mnt/cassandra:/var/lib/cassandra networks: - cluster_net ################################################################ # The Casandra cluster # - cassandra-node2 ################################################################ cassandra-002: image: cassandra:3.11 environment: CASSANDRA_BROADCAST_ADDRESS: "cassandra-002" CASSANDRA_SEEDS: "cassandra-001" deploy: restart_policy: condition: on-failure max_attempts: 3 window: 120s placement: constraints: - node.hostname == node-002 volumes: - /mnt/cassandra:/var/lib/cassandra networks: - cluster_net
I am running each cassandra service on a specific host within my docker-swarm. We can not use the build-in scaling feature of docker-swarm because we need to define a separate data volume for each service. See the section ‘volumes’.
The other important part are the two environment variables ‘CASSANDRA_BROADCAST_ADDRESS’ and ‘CASSANDRA_SEEDS’.
‘CASSANDRA_BROADCAST_ADDRESS’ defines a container name for each cassandra node within the cassandra cluster. This name matches the service name. As both services run in the same network ‘cluster_net’ the both cassandara nodes find each user via the service name.
The second environment ‘CASSANDRA_SEEDS’ defines the seed node which need to be defined for the second service only. This is necessary even if a cassandra cluster is ‘master-less’.
That’s is!
I read your blog about upgrading Cassandra from version 3.11 to 4.0. I noticed that configuration changes in the YAML file are necessary for this upgrade. Could you please provide some guidance on how to accomplish this, particularly in the context of a Docker Swarm cluster? Your assistance would be greatly appreciated.
I run my own cassandra cluster on bare metal nodes directly on Docker. So I do not use docker-swarm. Try first to succeed with running on docker directly. If it works than you can apply you setup into your docker-swarm environment. As I wrote, the port 7001 is disable now and you need to the new cassandra.yaml file.