Docker Community Forums

Share and learn in the Docker community.

Cassandra on Docker Swarm


(Nameen) #1

Can someone please post a link to a document or article on installing Cassandra on Docker Swarm?


(Nathan Le Claire) #2

I think you’ll have to write it :slight_smile:


(Azaars) #3

I run 3 Cassandra instances from docker stack deploy command that reads the following YML file:

version: '3'
services:
  cassandra-1:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra1
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-1
    volumes:
    - volume1:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
  cassandra-2:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra2
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-2
      CASSANDRA_SEEDS: cassandra-1
    depends_on:
      - cassandra-1
    volumes:
    - volume2:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
  cassandra-3:
    image: cassandra
    deploy:
      restart_policy:
        condition: on-failure
        max_attempts: 3
        window: 120s
      placement:
        constraints:
        - node.labels.db==cassandra3
    environment:
      CASSANDRA_BROADCAST_ADDRESS: cassandra-3
      CASSANDRA_SEEDS: cassandra-1
    depends_on:
      - cassandra-2
    volumes:
    - volume3:/var/lib/cassandra
    ports:
    - "7000"
    networks:
      default:
volumes:
  volume1:
    external:
        name: cassandra1-vol
  volume2:
    external:
        name: cassandra2-vol
  volume3:
    external:
        name: cassandra3-vol
networks:
  default:
    external:
       name: cassandra-net

Alternatively, each instance could be run individually from its docker service create counterpart with similar parameters.

As a side note, the custom node.labels.db==cassandra label is required in my setup because of the tight coupling with the volumes in a 3 managers + 5 workers cluster.


(Junius) #4

For Cassandra, the current docker volume plugin such as folcker, rexray, etc, could not help, as they could not setup the membership among Cassandra members. azaars’s solution is a reasonable way to setup Cassandra on Docker Swarm. While, if the node goes down, one Cassandra member will disappear. You would need additional work to bring up another node, and join the current Cassandra cluster. Cassandra will then recover data automatically.

FireCamp is a recent open source project aims to automate the installation and management of the stateful services, including Cassandra, on Docker Swarm. While, currently it only supports installing the stateful services for Docker Swarm on AWS. Hope it could help your case.


(Ryansuxena) #5

Hi Azzars,

You have created 3 services for Cassandra that means it is fixed to 3 only. what if you want scale up the Cassandra to 4 or 5 ?