Skip to content

Instantly share code, notes, and snippets.

@thejinxters
Last active May 23, 2016 03:57
Show Gist options
  • Save thejinxters/01f9e90809ad0de1e012 to your computer and use it in GitHub Desktop.
Save thejinxters/01f9e90809ad0de1e012 to your computer and use it in GitHub Desktop.

Getting Cassandra and OpsCenter to run on OSX using Docker

Getting Docker installed

Why not make life easy...? Install Homebrew

The 'brew' package lets you install applications through the commandline, making compiling and setting up new apps a breeze.

Since docker cannot run on osx natively, we will need to build a virtual machine to run it through. We will be using VirtualBox to run our virtual machines. The following commands install cask, a brew 'extension' for downloading mac applications in a linux-style way. For more info visit the Cask website

brew install cask
brew cask install virtualbox

Next we need to install docker, and it's sidekick boot2docker. The program boot2docker will give you an interface to run docker containers through a virtual machine. For more info visit Boot2Docker

brew install docker
brew install boot2docker

That should be all you need installed to run docker.

Loading Boot2Docker

To run docker we will need to create the boot2docker virtual machine and run it.

boot2docker init
boot2docker up

You will need to READ THE OUTPUT and add the environment variables to your .bashrc file. Ensure your DOCKER_HOST variable is set with echo $DOCKER_HOST

Now you can grab your the IP address of your boot2docker virtual machine.

boot2docker ip

Here is a little snippet that will temporarily store the IP address.

DOCKER_IP=$(boot2docker ip 2> /dev/null)

Fixing the IP Problems

Since we are running docker through a virtual machine, our docker instances will not be accessable through the localhost within our OSX machine. When we run a docker container, it will be mapped to a port on our virtual machine, and thus accessible through the boot2docker ip address.

Lets make it easy to so we don't have to type in an ip address every time we want to access our virtual machine. The following adds a line to your hosts file to redirect the world 'dockerhost' to the virtual machine IP.

echo $DOCKER_IP dockerhost | sudo tee -a /etc/hosts

Running Cassandra through Docker

Lets install cassandra and cql tools to get cassandra up and running. To do this we will need the cassandra package and the latest version of python. We will then use python's package manager to install the cassandra packages.

brew install cassandra
brew install python
pip install cql
pip install cassandra-driver

Okay, we are now ready to download and run our cassandra docker instance. For this I will be using the current most popular docker repository for Cassandra and OptCenter

docker pull abh1nav/cassandra:latest
docker run -d --name opscenter -p 8888:8888 abh1nav/opscenter:latest

This will create a new docker container called 'opscenter' that will run on port 8888 on the dockerhost ip. Lets store this ip/port for use in creating the cassandra cluster.

OPS_IP="$DOCKER_IP:8888"
docker run -d --name cass1 -e OPS_IP=$OPS_IP -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 abh1nav/cassandra:latest

Now your cassandra cluster is up and running, accessable through the default ports on your dockerhost. Try connecting to your cassandra server using cqlsh.

cqlsh $DOCKER_IP

If you did everything right, you should get a cql prompt! Now go to Planet Cassandra to learn how to use Cassandra!

Visit http://dockerhost:8888 to access OpsCenter and connect to your via the dockerhost ip.

YAY! You have successfully set up Docker, Cassandra and OpsCenter

Some cool sidenotes

A few of the steps above, I grabbed/modified fr om Chris Jones over at Viget.com. His article can be found here: How to use docker on OSX - the missing guide

He talks about more general Docker issues and fixes (like how to use 'VirtualBox Guest Additions' to share files with your host system and using nsenter to actually view the files inside your docker container).

Also, the repository we pulled from had instructions on how to get multiple clusters to work together through docker. This can be found at abh1nav's repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment