running_riak_service.rst 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. :title: Running a Riak service
  2. :description: Build a Docker image with Riak pre-installed
  3. :keywords: docker, example, package installation, networking, riak
  4. Riak Service
  5. ==============================
  6. .. include:: example_header.inc
  7. The goal of this example is to show you how to build a Docker image with Riak
  8. pre-installed.
  9. Creating a ``Dockerfile``
  10. +++++++++++++++++++++++++
  11. Create an empty file called ``Dockerfile``:
  12. .. code-block:: bash
  13. touch Dockerfile
  14. Next, define the parent image you want to use to build your image on top of.
  15. We’ll use `Ubuntu <https://index.docker.io/_/ubuntu/>`_ (tag: ``latest``),
  16. which is available on the `docker index <http://index.docker.io>`_:
  17. .. code-block:: bash
  18. # Riak
  19. #
  20. # VERSION 0.1.0
  21. # Use the Ubuntu base image provided by dotCloud
  22. FROM ubuntu:latest
  23. MAINTAINER Hector Castro hector@basho.com
  24. Next, we update the APT cache and apply any updates:
  25. .. code-block:: bash
  26. # Update the APT cache
  27. RUN sed -i.bak 's/main$/main universe/' /etc/apt/sources.list
  28. RUN apt-get update
  29. RUN apt-get upgrade -y
  30. After that, we install and setup a few dependencies:
  31. - ``curl`` is used to download Basho's APT repository key
  32. - ``lsb-release`` helps us derive the Ubuntu release codename
  33. - ``openssh-server`` allows us to login to containers remotely and join Riak
  34. nodes to form a cluster
  35. - ``supervisor`` is used manage the OpenSSH and Riak processes
  36. .. code-block:: bash
  37. # Install and setup project dependencies
  38. RUN apt-get install -y curl lsb-release supervisor openssh-server
  39. RUN mkdir -p /var/run/sshd
  40. RUN mkdir -p /var/log/supervisor
  41. RUN locale-gen en_US en_US.UTF-8
  42. ADD supervisord.conf /etc/supervisor/conf.d/supervisord.conf
  43. RUN echo 'root:basho' | chpasswd
  44. Next, we add Basho's APT repository:
  45. .. code-block:: bash
  46. RUN curl -s http://apt.basho.com/gpg/basho.apt.key | apt-key add --
  47. RUN echo "deb http://apt.basho.com $(lsb_release -cs) main" > /etc/apt/sources.list.d/basho.list
  48. RUN apt-get update
  49. After that, we install Riak and alter a few defaults:
  50. .. code-block:: bash
  51. # Install Riak and prepare it to run
  52. RUN apt-get install -y riak
  53. RUN sed -i.bak 's/127.0.0.1/0.0.0.0/' /etc/riak/app.config
  54. RUN echo "ulimit -n 4096" >> /etc/default/riak
  55. Almost there. Next, we add a hack to get us by the lack of ``initctl``:
  56. .. code-block:: bash
  57. # Hack for initctl
  58. # See: https://github.com/dotcloud/docker/issues/1024
  59. RUN dpkg-divert --local --rename --add /sbin/initctl
  60. RUN ln -s /bin/true /sbin/initctl
  61. Then, we expose the Riak Protocol Buffers and HTTP interfaces, along with SSH:
  62. .. code-block:: bash
  63. # Expose Riak Protocol Buffers and HTTP interfaces, along with SSH
  64. EXPOSE 8087 8098 22
  65. Finally, run ``supervisord`` so that Riak and OpenSSH are started:
  66. .. code-block:: bash
  67. CMD ["/usr/bin/supervisord"]
  68. Create a ``supervisord`` configuration file
  69. +++++++++++++++++++++++++++++++++++++++++++
  70. Create an empty file called ``supervisord.conf``. Make sure it's at the same
  71. directory level as your ``Dockerfile``:
  72. .. code-block:: bash
  73. touch supervisord.conf
  74. Populate it with the following program definitions:
  75. .. code-block:: bash
  76. [supervisord]
  77. nodaemon=true
  78. [program:sshd]
  79. command=/usr/sbin/sshd -D
  80. stdout_logfile=/var/log/supervisor/%(program_name)s.log
  81. stderr_logfile=/var/log/supervisor/%(program_name)s.log
  82. autorestart=true
  83. [program:riak]
  84. command=bash -c ". /etc/default/riak && /usr/sbin/riak console"
  85. pidfile=/var/log/riak/riak.pid
  86. stdout_logfile=/var/log/supervisor/%(program_name)s.log
  87. stderr_logfile=/var/log/supervisor/%(program_name)s.log
  88. Build the Docker image for Riak
  89. +++++++++++++++++++++++++++++++
  90. Now you should be able to build a Docker image for Riak:
  91. .. code-block:: bash
  92. docker build -t "<yourname>/riak" .
  93. Next steps
  94. ++++++++++
  95. Riak is a distributed database. Many production deployments consist of `at
  96. least five nodes <http://basho.com/why-your-riak-cluster-should-have-at-least-
  97. five-nodes/>`_. See the `docker-riak <https://github.com/hectcastro /docker-
  98. riak>`_ project details on how to deploy a Riak cluster using Docker and
  99. Pipework.