puppet.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. :title: Puppet Usage
  2. :description: Installating and using Puppet
  3. :keywords: puppet, installation, usage, docker, documentation
  4. .. _install_using_puppet:
  5. Using Puppet
  6. =============
  7. .. note::
  8. Please note this is a community contributed installation path. The
  9. only 'official' installation is using the :ref:`ubuntu_linux`
  10. installation path. This version may sometimes be out of date.
  11. Requirements
  12. ------------
  13. To use this guide you'll need a working installation of Puppet from
  14. `Puppetlabs <https://www.puppetlabs.com>`_ .
  15. The module also currently uses the official PPA so only works with Ubuntu.
  16. Installation
  17. ------------
  18. The module is available on the `Puppet Forge
  19. <https://forge.puppetlabs.com/garethr/docker/>`_ and can be installed
  20. using the built-in module tool.
  21. .. code-block:: bash
  22. puppet module install garethr/docker
  23. It can also be found on `GitHub
  24. <https://www.github.com/garethr/garethr-docker>`_ if you would rather
  25. download the source.
  26. Usage
  27. -----
  28. The module provides a puppet class for installing Docker and two defined types
  29. for managing images and containers.
  30. Installation
  31. ~~~~~~~~~~~~
  32. .. code-block:: ruby
  33. include 'docker'
  34. Images
  35. ~~~~~~
  36. The next step is probably to install a Docker image. For this, we have a
  37. defined type which can be used like so:
  38. .. code-block:: ruby
  39. docker::image { 'ubuntu': }
  40. This is equivalent to running:
  41. .. code-block:: bash
  42. docker pull ubuntu
  43. Note that it will only be downloaded if an image of that name does
  44. not already exist. This is downloading a large binary so on first
  45. run can take a while. For that reason this define turns off the
  46. default 5 minute timeout for the exec type. Note that you can also
  47. remove images you no longer need with:
  48. .. code-block:: ruby
  49. docker::image { 'ubuntu':
  50. ensure => 'absent',
  51. }
  52. Containers
  53. ~~~~~~~~~~
  54. Now you have an image where you can run commands within a container
  55. managed by Docker.
  56. .. code-block:: ruby
  57. docker::run { 'helloworld':
  58. image => 'ubuntu',
  59. command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
  60. }
  61. This is equivalent to running the following command, but under upstart:
  62. .. code-block:: bash
  63. docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"
  64. Run also contains a number of optional parameters:
  65. .. code-block:: ruby
  66. docker::run { 'helloworld':
  67. image => 'ubuntu',
  68. command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
  69. ports => ['4444', '4555'],
  70. volumes => ['/var/lib/couchdb', '/var/log'],
  71. volumes_from => '6446ea52fbc9',
  72. memory_limit => 10485760, # bytes
  73. username => 'example',
  74. hostname => 'example.com',
  75. env => ['FOO=BAR', 'FOO2=BAR2'],
  76. dns => ['8.8.8.8', '8.8.4.4'],
  77. }
  78. Note that ports, env, dns and volumes can be set with either a single string
  79. or as above with an array of values.