2014-05-21 17:05:19 -04:00
|
|
|
page_title: Dockerizing a Riak service
|
2014-04-15 20:53:12 -04:00
|
|
|
page_description: Build a Docker image with Riak pre-installed
|
|
|
|
page_keywords: docker, example, package installation, networking, riak
|
|
|
|
|
2014-05-21 17:05:19 -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:
|
2014-06-01 16:48:04 -04:00
|
|
|
`latest`), which is available on [Docker Hub](https://hub.docker.com):
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
# Riak
|
|
|
|
#
|
|
|
|
# VERSION 0.1.0
|
|
|
|
|
|
|
|
# Use the Ubuntu base image provided by dotCloud
|
|
|
|
FROM ubuntu:latest
|
|
|
|
MAINTAINER Hector Castro hector@basho.com
|
|
|
|
|
|
|
|
After that, we install and setup a few dependencies:
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
- `curl` is used to download Basho's APT
|
2014-04-15 20:53:12 -04:00
|
|
|
repository key
|
2014-04-23 16:48:28 -04:00
|
|
|
- `lsb-release` helps us derive the Ubuntu release
|
2014-04-15 20:53:12 -04:00
|
|
|
codename
|
2014-04-23 16:48:28 -04:00
|
|
|
- `openssh-server` allows us to login to
|
2014-04-15 20:53:12 -04:00
|
|
|
containers remotely and join Riak nodes to form a cluster
|
2014-04-23 16:48:28 -04:00
|
|
|
- `supervisor` is used manage the OpenSSH and Riak
|
2014-04-15 20:53:12 -04:00
|
|
|
processes
|
|
|
|
|
|
|
|
<!-- -->
|
|
|
|
|
|
|
|
# Install and setup project dependencies
|
2014-07-07 14:06:34 -04:00
|
|
|
RUN apt-get update && apt-get install -y curl lsb-release supervisor openssh-server
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
RUN mkdir -p /var/run/sshd
|
|
|
|
RUN mkdir -p /var/log/supervisor
|
|
|
|
|
|
|
|
RUN locale-gen en_US en_US.UTF-8
|
|
|
|
|
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
|
|
|
|
|
|
|
RUN echo 'root:basho' | chpasswd
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
Next, we add Basho's APT repository:
|
2014-04-15 20:53:12 -04:00
|
|
|
|
2014-07-07 12:35:38 -04:00
|
|
|
RUN curl -sSL http://apt.basho.com/gpg/basho.apt.key | apt-key add --
|
2014-04-15 20:53:12 -04:00
|
|
|
RUN echo "deb http://apt.basho.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/basho.list
|
|
|
|
|
|
|
|
After that, we install Riak and alter a few defaults:
|
|
|
|
|
|
|
|
# Install Riak and prepare it to run
|
2014-07-07 14:06:34 -04:00
|
|
|
RUN apt-get update && apt-get install -y riak
|
2014-04-15 20:53:12 -04:00
|
|
|
RUN sed -i.bak 's/127.0.0.1/0.0.0.0/' /etc/riak/app.config
|
|
|
|
RUN echo "ulimit -n 4096" >> /etc/default/riak
|
|
|
|
|
|
|
|
Then, we expose the Riak Protocol Buffers and HTTP interfaces, along
|
|
|
|
with SSH:
|
|
|
|
|
|
|
|
# Expose Riak Protocol Buffers and HTTP interfaces, along with SSH
|
|
|
|
EXPOSE 8087 8098 22
|
|
|
|
|
|
|
|
Finally, run `supervisord` so that Riak and OpenSSH
|
|
|
|
are started:
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
[program:sshd]
|
|
|
|
command=/usr/sbin/sshd -D
|
|
|
|
stdout_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
stderr_logfile=/var/log/supervisor/%(program_name)s.log
|
|
|
|
autorestart=true
|
|
|
|
|
|
|
|
[program:riak]
|
|
|
|
command=bash -c ". /etc/default/riak && /usr/sbin/riak console"
|
|
|
|
pidfile=/var/log/riak/riak.pid
|
|
|
|
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:
|
|
|
|
|
2014-09-15 21:49:05 -04:00
|
|
|
$ sudo 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.
|