Cassandra in docker.
Apache cassandra is an open source database management system designed to handle huge aounts of data in a highly available (no single point of failure), distributed way.
You can either build it yourself, or pull it from the Docker Registry.
docker build [--rm] -t docxs/cassandra .
docker pull docxs/cassandra
Once the image is on your system, you can run it in different configurations or for different purposes (see below). There's a couple of environment variables you can provide during runtime, to customize the configuration. These are:
CASSANDRA_LISTEN_ADDRESS
Variable for controlling which IP address cassandra is listening on for incoming connections (listen_address in cassandra.yaml). The default value is automatically set to the ip address of the docker instance as it starts, and should work most of the time.
CASSANDRA_BROADCAST_ADDRESS
Variable for controlling the IP address Cassandra is advertising to other nodes (sets broadcast_address and broadcast_rpc_address in cassandra.yaml). By default, it is set to $CASSANDRA_LISTEN_ADDRESS. It can never be assigned the wildcard address (0.0.0.0).
CASSANDRA_SEEDS
Variable that should contain a comma separated list of the IP addresses used by gossip for bootstrapping new nodes joining a cluster (seeds of seed_provider in cassandra.yaml). It adds the $CASSANDRA_BROADCAST_ADDRESS to the list, so the instance will talk to itself as well.
CASSANDRA_CLUSTERNAME
Variable for setting the cluster name (cluster_name in cassandra.yaml), which must be the same for all nodes in the cluster. Defaults to MyCluster.
CASSANDRA_NUM_TOKENS
Variable setting the number of tokens for this instance (num_tokens in cassandra.yaml). Defaults to 256.
CASSANDRA_DATACENTER
Variable setting the datacenter name of this node (dc in cassandra-rackdc.properties). Defaults to DC1.
CASSANDRA_RACK
Variable setting the datacenter name of this node (rack in cassandra-rackdc.properties). Defaults to RAC1.
CASSANDRA_ENDPOINT_SNITCH
Variable setting the snitch implementation this node will use (endpoint_snitch in cassandra.yaml). Defaults to SimpleSnitch.
CASSANDRA_MAX_HEAP
Defaults to 1024M
CASSANDRA_NEW_HEAP
Defaults to 256M
All data is saved in the /data folder of the container. If you don't want the data to be ephemeral, you can map the folder to one of the docker host system, or to a docker data container.
-cassandra: runs cassandra-server (default)-cqlsh: runs cqlsh (with arguments)-nodetool: runs nodetool (with arguments)-bash: run the container with a shell sessionSome examples:
Ephemeral data in the container, and ports not mapped to the host system
docker run -d [--name <name>] \
<user>/cassandra
... where ` is the name you want to assign to your container.
Persistent data on the host system, and use the hosts net stack for connection:
docker run -d [--name <name>] \
-v <data_folder>:/data \
--net=host \
<user>/cassandra
There are 2 cluster scenarios
Run the first container that will act as the seed, and get the seed's ip address:
docker run -d [--name <name>] \
<user>/cassandra
Then run the nth node as follows:
docker run -d [--name <name_i>] \
-e "CASSANDRA_SEEDS=<seed_ip>"
<user>/cassandra
Connect to Cassandra using cqlsh from the docker image
You can connect to Cassandra directly by providing the ip address:
docker run -it --rm
<user>/cassandra -cqlsh <ip>
... or you can use docker linking to make the Cassandra instance available to your cqlsh application container:
docker run -it --rm
--link <name>:<link-name>
<user>/cassandra -cqlsh <link-name>
... where is the freely to choose hostname of the Cassandra instance within the cqlsh application container, and is the name of the Cassandra instance
Connect to Cassandra from any other application
If the application is not run from within a docker container, you can connect to the Cassandra instance if you properly map the ports to the host system. If the application is run from within a docker image on the same host, you can follow the pattern given above for cqlsh. Example:
docker run --name app
--link <name>:<link-name>
-d <app-using-cassandra>
Licensed under the MIT License. See the LICENSE file for details.
Are welcome!
Content type
Image
Digest
sha256:104a833f8…
Size
150.3 MB
Last updated
over 10 years ago
docker pull docxs/cassandra