Docker - Riak in Docker

February 21, 2017    docker riak

Riak was designed to be deployed and run on dedicated infrastructure, as opposed to containers or virtualization platforms.

Nonetheless, being able to quickly deploy a Riak cluster for testing and development purposes can be very useful.

I’ve created a repository today that enables the user to build Docker images for most versions of Riak KV, TS, and CS ever produced:

The dockerfile is relatively simple:

FROM centos:7

ARG major_version

ARG minor_version

RUN yum install -y -q iproute

RUN yum install -y -q${major_version}/${major_version}.${minor_version}/rhel/7/riak-${major_version}.${minor_version}-1.el7.centos.x86_64.rpm

ADD /usr/bin/riak-docker

CMD riak-docker

The script used to start the Riak service takes care of some basic configuration and then tails the logs:

remove stale entries

sed -i ‘/nodename/d’ /etc/riak/riak.conf sed -i ‘/listener.http.internal/d’ /etc/riak/riak.conf sed -i ‘/listener.protobuf.internal/d’ /etc/riak/riak.conf

configure the node

IPV4=$(ip -4 addr show eth0 | grep -oP ‘(?<=inet\s)\d+(.\d+){3}‘) NODENAME=“riak@${IPV4}” cat << EOF >> /etc/riak/riak.conf

Added By riak-docker

nodename = $NODENAME listener.http.internal = $IPV4:8098 listener.protobuf.internal = $IPV4:8087 EOF

start Riak

riak start

trap signals

trap “riak stop” SIGTERM SIGINT

follow the logs

tail -f /var/log/riak/* & JOB=$!

wait for signals

wait $!

Using these images, creation of a node becomes a breeze:
docker run -d –name riak-kv-2-2-0-1 shaneutt/riak-kv:2.2.0
Then you can simply add enough nodes to make a five node cluster (and wait for them to come up):
for i in $(seq 2 5); do docker run -d –name riak-kv-2-2-0-$i shaneutt/riak_kv:2.2.0; done
for i in $(seq 2 5); do docker exec riak-kv-2-2-0-$i riak-admin wait_for_service riak_kv; done
And then join all the nodes together, plan, and commit!
export NODEIP=$(docker inspect riak-kv-2-2-0-1 |awk -F ‘“’ ‘/“IPAddress”/{print$4}’|head -1)
for i in $(seq 2 5); do docker exec riak-kv-2-2-0-$i riak-admin cluster join riak@${NODEIP}; done
docker exec riak-kv-2-2-0-1 riak-admin cluster plan
docker exec riak-kv-2-2-0-1 riak-admin cluster commit
Now you have a Riak test environment to test your apps against, woohoo!

Happy Coding!


comments powered by Disqus