2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
|
|
|
title = "Dockerizing a Riak service"
|
|
|
|
description = "Build a Docker image with Riak pre-installed"
|
|
|
|
keywords = ["docker, example, package installation, networking, riak"]
|
|
|
|
[menu.main]
|
|
|
|
parent = "smn_apps_servs"
|
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-04-21 11:50:09 -04:00
|
|
|
# Dockerizing a Riak service
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
The goal of this example is to show you how to build a Docker image with
|
|
|
|
Riak pre-installed.
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
## Creating a Dockerfile
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-05-21 17:05:19 -04:00
|
|
|
Create an empty file called `Dockerfile`:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-05-01 10:13:34 -04:00
|
|
|
$ touch Dockerfile
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
Next, define the parent image you want to use to build your image on top
|
2014-07-07 09:52:18 -04:00
|
|
|
of. We'll use [Ubuntu](https://registry.hub.docker.com/_/ubuntu/) (tag:
|
2015-03-27 14:18:40 -04:00
|
|
|
`trusty`), which is available on [Docker Hub](https://hub.docker.com):
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
# Riak
|
|
|
|
#
|
2015-03-27 14:18:40 -04:00
|
|
|
# VERSION 0.1.1
|
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
# Use the Ubuntu base image provided by dotCloud
|
2015-03-27 14:18:40 -04:00
|
|
|
FROM ubuntu:trusty
|
2014-04-15 20:53:12 -04:00
|
|
|
MAINTAINER Hector Castro hector@basho.com
|
|
|
|
|
2015-03-27 14:18:40 -04:00
|
|
|
After that, we install the curl which is used to download the repository setup
|
|
|
|
script and we download the setup script and run it.
|
|
|
|
|
|
|
|
# Install Riak repository before we do apt-get update, so that update happens
|
|
|
|
# in a single step
|
|
|
|
RUN apt-get install -q -y curl && \
|
|
|
|
curl -sSL https://packagecloud.io/install/repositories/basho/riak/script.deb | sudo bash
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-27 14:18:40 -04:00
|
|
|
Then we install and setup a few dependencies:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-24 22:27:58 -04:00
|
|
|
- `supervisor` is used manage the Riak processes
|
2015-03-27 14:18:40 -04:00
|
|
|
- `riak=2.0.5-1` is the Riak package coded to version 2.0.5
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
<!-- -->
|
|
|
|
|
|
|
|
# Install and setup project dependencies
|
2015-03-27 14:18:40 -04:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y supervisor riak=2.0.5-1
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
RUN mkdir -p /var/log/supervisor
|
2015-03-27 14:18:40 -04:00
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
RUN locale-gen en_US en_US.UTF-8
|
2015-03-27 14:18:40 -04:00
|
|
|
|
2014-07-09 17:13:26 -04:00
|
|
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-27 14:18:40 -04:00
|
|
|
After that, we modify Riak's configuration:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-27 14:18:40 -04:00
|
|
|
# Configure Riak to accept connections from any host
|
|
|
|
RUN sed -i "s|listener.http.internal = 127.0.0.1:8098|listener.http.internal = 0.0.0.0:8098|" /etc/riak/riak.conf
|
|
|
|
RUN sed -i "s|listener.protobuf.internal = 127.0.0.1:8087|listener.protobuf.internal = 0.0.0.0:8087|" /etc/riak/riak.conf
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-05-03 14:15:17 -04:00
|
|
|
Then, we expose the Riak Protocol Buffers and HTTP interfaces:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-24 22:27:58 -04:00
|
|
|
# Expose Riak Protocol Buffers and HTTP interfaces
|
|
|
|
EXPOSE 8087 8098
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2015-03-27 14:18:40 -04:00
|
|
|
Finally, run `supervisord` so that Riak is started:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
CMD ["/usr/bin/supervisord"]
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
## Create a supervisord configuration file
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
Create an empty file called `supervisord.conf`. Make
|
2014-05-21 17:05:19 -04:00
|
|
|
sure it's at the same directory level as your `Dockerfile`:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
touch supervisord.conf
|
|
|
|
|
|
|
|
Populate it with the following program definitions:
|
|
|
|
|
|
|
|
[supervisord]
|
|
|
|
nodaemon=true
|
2015-03-27 14:18:40 -04:00
|
|
|
|
2014-04-15 20:53:12 -04:00
|
|
|
[program:riak]
|
2015-03-27 14:18:40 -04:00
|
|
|
command=bash -c "/usr/sbin/riak console"
|
|
|
|
numprocs=1
|
|
|
|
autostart=true
|
|
|
|
autorestart=true
|
|
|
|
user=riak
|
|
|
|
environment=HOME="/var/lib/riak"
|
2014-04-15 20:53:12 -04:00
|
|
|
stdout_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
stderr_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
|
|
|
|
## Build the Docker image for Riak
|
|
|
|
|
|
|
|
Now you should be able to build a Docker image for Riak:
|
|
|
|
|
2015-03-26 14:12:37 -04:00
|
|
|
$ docker build -t "<yourname>/riak" .
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
## Next steps
|
|
|
|
|
|
|
|
Riak is a distributed database. Many production deployments consist of
|
2014-04-23 16:48:28 -04:00
|
|
|
[at least five nodes](
|
|
|
|
http://basho.com/why-your-riak-cluster-should-have-at-least-five-nodes/).
|
2014-04-15 20:53:12 -04:00
|
|
|
See the [docker-riak](https://github.com/hectcastro/docker-riak) project
|
|
|
|
details on how to deploy a Riak cluster using Docker and Pipework.
|