2014-05-21 21:05:19 +00:00
|
|
|
page_title: Dockerizing a Riak service
|
2014-04-16 00:53:12 +00:00
|
|
|
page_description: Build a Docker image with Riak pre-installed
|
|
|
|
page_keywords: docker, example, package installation, networking, riak
|
|
|
|
|
2014-05-21 21:05:19 +00:00
|
|
|
# Dockerizing a Riak Service
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
The goal of this example is to show you how to build a Docker image with
|
|
|
|
Riak pre-installed.
|
|
|
|
|
2014-04-23 20:48:28 +00:00
|
|
|
## Creating a Dockerfile
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2014-05-21 21:05:19 +00:00
|
|
|
Create an empty file called `Dockerfile`:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2014-05-01 14:13:34 +00:00
|
|
|
$ touch Dockerfile
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
Next, define the parent image you want to use to build your image on top
|
2014-07-07 13:52:18 +00:00
|
|
|
of. We'll use [Ubuntu](https://registry.hub.docker.com/_/ubuntu/) (tag:
|
2015-03-27 18:18:40 +00:00
|
|
|
`trusty`), which is available on [Docker Hub](https://hub.docker.com):
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
# Riak
|
|
|
|
#
|
2015-03-27 18:18:40 +00:00
|
|
|
# VERSION 0.1.1
|
|
|
|
|
2014-04-16 00:53:12 +00:00
|
|
|
# Use the Ubuntu base image provided by dotCloud
|
2015-03-27 18:18:40 +00:00
|
|
|
FROM ubuntu:trusty
|
2014-04-16 00:53:12 +00:00
|
|
|
MAINTAINER Hector Castro hector@basho.com
|
|
|
|
|
2015-03-27 18:18:40 +00: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-16 00:53:12 +00:00
|
|
|
|
2015-03-27 18:18:40 +00:00
|
|
|
Then we install and setup a few dependencies:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2015-03-25 02:27:58 +00:00
|
|
|
- `supervisor` is used manage the Riak processes
|
2015-03-27 18:18:40 +00:00
|
|
|
- `riak=2.0.5-1` is the Riak package coded to version 2.0.5
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
<!-- -->
|
|
|
|
|
|
|
|
# Install and setup project dependencies
|
2015-03-27 18:18:40 +00:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y supervisor riak=2.0.5-1
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
RUN mkdir -p /var/log/supervisor
|
2015-03-27 18:18:40 +00:00
|
|
|
|
2014-04-16 00:53:12 +00:00
|
|
|
RUN locale-gen en_US en_US.UTF-8
|
2015-03-27 18:18:40 +00:00
|
|
|
|
2014-07-09 21:13:26 +00:00
|
|
|
COPY supervisord.conf /etc/supervisor/conf.d/supervisord.conf
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2015-03-27 18:18:40 +00:00
|
|
|
After that, we modify Riak's configuration:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2015-03-27 18:18:40 +00: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-16 00:53:12 +00:00
|
|
|
|
|
|
|
Then, we expose the Riak Protocol Buffers and HTTP interfaces, along
|
|
|
|
with SSH:
|
|
|
|
|
2015-03-25 02:27:58 +00:00
|
|
|
# Expose Riak Protocol Buffers and HTTP interfaces
|
|
|
|
EXPOSE 8087 8098
|
2014-04-16 00:53:12 +00:00
|
|
|
|
2015-03-27 18:18:40 +00:00
|
|
|
Finally, run `supervisord` so that Riak is started:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
CMD ["/usr/bin/supervisord"]
|
|
|
|
|
2014-04-23 20:48:28 +00:00
|
|
|
## Create a supervisord configuration file
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
Create an empty file called `supervisord.conf`. Make
|
2014-05-21 21:05:19 +00:00
|
|
|
sure it's at the same directory level as your `Dockerfile`:
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
touch supervisord.conf
|
|
|
|
|
|
|
|
Populate it with the following program definitions:
|
|
|
|
|
|
|
|
[supervisord]
|
|
|
|
nodaemon=true
|
2015-03-27 18:18:40 +00:00
|
|
|
|
2014-04-16 00:53:12 +00:00
|
|
|
[program:riak]
|
2015-03-27 18:18:40 +00:00
|
|
|
command=bash -c "/usr/sbin/riak console"
|
|
|
|
numprocs=1
|
|
|
|
autostart=true
|
|
|
|
autorestart=true
|
|
|
|
user=riak
|
|
|
|
environment=HOME="/var/lib/riak"
|
2014-04-16 00:53:12 +00: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 18:12:37 +00:00
|
|
|
$ docker build -t "<yourname>/riak" .
|
2014-04-16 00:53:12 +00:00
|
|
|
|
|
|
|
## Next steps
|
|
|
|
|
|
|
|
Riak is a distributed database. Many production deployments consist of
|
2014-04-23 20:48:28 +00:00
|
|
|
[at least five nodes](
|
|
|
|
http://basho.com/why-your-riak-cluster-should-have-at-least-five-nodes/).
|
2014-04-16 00:53:12 +00:00
|
|
|
See the [docker-riak](https://github.com/hectcastro/docker-riak) project
|
|
|
|
details on how to deploy a Riak cluster using Docker and Pipework.
|