使用 Puppet


为了使用这个说明,你先要通过这个文档Puppetlabs安装Puppet .

The module also currently uses the official PPA so only works with Ubuntu.


The module is available on the Puppet Forge and can be installed using the built-in module tool.

puppet module install garethr/docker

It can also be found on GitHub if you would rather download the source.


The module provides a puppet class for installing docker and two defined types for managing images and containers.


include 'docker'



docker::image { 'ubuntu': }

This is equivalent to running:

docker pull ubuntu

Note that it will only if the image of that name does not already exist. This is downloading a large binary so on first run can take a while. For that reason this define turns off the default 5 minute timeout for exec. Note that you can also remove images you no longer need with:

docker::image { 'ubuntu':
ensure => 'absent',}


Now you have an image you can run commands within a container managed by docker.

docker::run { 'helloworld':
image => 'ubuntu',
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',}

This is equivalent to running the following command, but under upstart:

docker run -d ubuntu /bin/sh -c "while true; do echo hello world; sleep 1; done"

Run also contains a number of optional parameters:

docker::run { 'helloworld':
image => 'ubuntu',
command => '/bin/sh -c "while true; do echo hello world; sleep 1; done"',
ports => ['4444', '4555'],
volumes => ['/var/lib/counchdb', '/var/log'],
volumes_from => '6446ea52fbc9',
memory_limit => 10485760, # bytes
username => 'example',
hostname => '',
env => ['FOO=BAR', 'FOO2=BAR2'],
dns => ['', ''],}

Note that ports, env, dns and volumes can be set with either a single string or as above with an array of values.