puppet.rst 2.8 KB

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