Skip to content

stide/chef-docker

Repository files navigation

chef-docker Build Status

Description

Installs/Configures Docker. Please see COMPATIBILITY.md for more information about Docker versions that are tested and supported by cookbook versions along with LWRP features.

This cookbook was inspired by @thoward's docker-cookbook: https://github.com/thoward/docker-cookbook

Requirements

Chef

  • Chef 11+

Platforms

  • Amazon 2014.03.1 (experimental)
  • CentOS 6
  • Debian 7
  • Fedora 19, 20
  • Mac OS X (only docker installation currently)
  • Oracle 6
  • RHEL 6
  • Ubuntu 12.04, 12.10, 13.04, 13.10, 14.04 (experimental)

Cookbooks

Opscode Cookbooks

Third-Party Cookbooks

Usage

Default Installation

  • Add recipe[docker] to your node's run list

Execution Drivers

If your system is running a Docker version before 0.9, you'll need to explicitly set up LXC outside of this cookbook. This will likely be true for most distros after Docker 1.0 and chef-docker 1.0 is released.

Storage Drivers

Beginning in chef-docker 1.0, storage driver installation and configuration is expected to be handled before this cookbook's execution, except where required by Docker.

AUFS

If you need AUFS support, consider adding the aufs cookbook to your node/recipe before docker.

Then, set the storage_driver attribute of this cookbook to aufs.

device-mapper

If you need device-mapper support, consider adding the device-mapper cookbook to your node/recipe before docker.

Then, set the storage_driver attribute of this cookbook to devicemapper (please note lack of dash).

Ubuntu 14.04 Package Installation via Docker PPA

By default, this cookbook will use the docker.io package from Ubuntu 14.04's repository. To use the Docker PPA package, just set the repo_url attribute to the Docker PPA URL. e.g. node.set['docker']['package']['repo_url'] = 'https://get.docker.io/ubuntu'

Attributes

Installation/System Attributes

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
archArchitecture for docker binary (note: Docker only currently supports x86_64)Stringauto-detected (see attributes/default.rb)
group_membersUsers to manage in node['docker']['group']Array of Strings[]
init_typeInit type for docker ("runit", "systemd", "sysv", or "upstart")Stringauto-detected (see attributes/default.rb)
install_dirInstallation directory for docker binary (custom setting only valid for non-package installations)Stringauto-detected (see attributes/default.rb)
install_typeInstallation type for docker ("binary", "package" or "source")Stringpackage
ipv4_forwardSysctl set net.ipv4.ip_forward to 1TrueClass, FalseClasstrue
ipv6_forwardSysctl set net.ipv6.conf.all.forwarding to 1TrueClass, FalseClasstrue
versionVersion of dockerStringnil

Binary Installation Attributes

These attributes are under the node['docker']['binary'] namespace.

AttributeDescriptionTypeDefault
checksumOptional SHA256 checksum for docker binaryStringauto-detected (see attributes/default.rb)
versionVersion of docker binaryStringnode['docker']['version'] (if set) or latest
urlURL for downloading docker binaryStringhttp://get.docker.io/builds/#{node['kernel']['name']}/#{node['docker']['arch']}/docker-#{node['docker']['binary']['version']}

Package Installation Attributes

These attributes are under the node['docker']['package'] namespace.

AttributeDescriptionTypeDefault
actionAction for docker packages ("install", "update", etc.)Stringinstall
distributionDistribution for docker packagesStringauto-detected (see attributes/default.rb)
nameOverride Docker package nameStringauto-detected (see attributes/default.rb)
repo_urlRepository URL for docker packagesStringauto-detected (see attributes/default.rb)
repo_keyRepository GPG key URL for docker packagesStringhttps://get.docker.io/gpg

Source Installation Attributes

These attributes are under the node['docker']['source'] namespace.

AttributeDescriptionTypeDefault
refRepository reference for docker sourceStringmaster
urlRepository URL for docker sourceStringhttps://github.com/dotcloud/docker.git

Docker Daemon Attributes

For more information: http://docs.docker.io/en/latest/reference/commandline/cli/#daemon

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
api_enable_corsEnable CORS headers in APITrueClass, FalseClassnil
bind_socket (DEPRECATED)Socket path that docker should bindStringunix:///var/run/docker.sock
bind_uri (DEPRECATED)TCP URI docker should bindStringnil
bipUse this CIDR notation address for the network bridge's IP, not compatible with bridgeStringnil
bridgeAttach containers to a pre-existing network bridge; use 'none' to disable container networkingStringnil
debugEnable debug modeTrueClass, FalseClassnil (implicitly false)
dnsDNS server(s) for containersString, Arraynil
dns_searchDNS search domain(s) for containersString, Arraynil
exec_driverExecution driver for dockerStringnil (implicitly native as of 0.9.0)
graphPath to use as the root of the docker runtimeStringnil (implicitly /var/lib/docker)
groupGroup for docker socket and group_membersStringnil (implicitly docker)
hostSocket(s) that docker should bindString, Arrayunix:///var/run/docker.sock
http_proxyHTTP_PROXY environment variableStringnil
iccEnable inter-container communicationTrueClass, FalseClassnil (implicitly true)
ipDefault IP address to use when binding container portsStringnil (implicitly 0.0.0.0)
iptablesEnable Docker's addition of iptables rulesTrueClass, FalseClassnil (implicitly true)
logfileSet custom DOCKER_LOGFILEStringnil
mtuSet the containers network MTUFixnumnil (implicitly default route MTU or 1500 if no default route is available)
optionsAdditional options to pass to docker. These could be flags like "-api-enable-cors".Stringnil
pidfilePath to use for daemon PID fileStringnil (implicitly /var/run/docker.pid)
ramdiskSet DOCKER_RAMDISK when using RAM diskTrueClass or FalseClassfalse
selinux_enabledEnable SELinuxTrueClass or FalseClassnil
storage_driverStorage driver for dockerStringnil
storage_optStorage driver optionsString, Arraynil
tlsUse TLSTrueClass, FalseClassnil (implicitly false)
tlscacertTrust only remotes providing a certificate signed by the CA given hereStringnil (implicitly ~/.docker/ca.pem)
tlscertPath to TLS certificate fileStringnil (implicitly ~/.docker/cert.pem)
tlskeyPath to TLS key fileStringnil (implicitly ~/.docker/key.pem)
tlsverifyUse TLS and verify the remote (daemon: verify client, client: verify daemon)TrueClass, FalseClassnil (implicitly false)
tmpdirTMPDIR environment variableStringnil

LWRP Attributes

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
docker_daemon_timeoutTimeout to wait for the docker daemon to start in seconds for LWRP commandsFixnum10

docker_container Attributes

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
container_cmd_timeoutcontainer LWRP default cmd_timeout secondsFixnum60
container_init_typeInit type for docker containers (nil, "runit", "systemd", "sysv", or "upstart")Stringnode['docker']['init_type']

docker_image Attributes

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
image_cmd_timeoutimage LWRP default cmd_timeout secondsFixnum300

docker_registry Attributes

These attributes are under the node['docker'] namespace.

AttributeDescriptionTypeDefault
registry_cmd_timeoutregistry LWRP default cmd_timeout secondsFixnum60

Recipes

  • recipe[docker] Installs/Configures Docker
  • recipe[docker::aufs] Installs/Loads AUFS Linux module
  • recipe[docker::binary] Installs Docker binary
  • recipe[docker::cgroups] Installs/configures default platform Control Groups support
  • recipe[docker::devicemapper] Installs/Configures Device Mapper
  • recipe[docker::group] Installs/Configures docker group
  • recipe[docker::lxc] Installs/configures default platform LXC support
  • recipe[docker::package] Installs Docker via package
  • recipe[docker::runit] Installs/Starts Docker via runit
  • recipe[docker::source] Installs Docker via source
  • recipe[docker::systemd] Installs/Starts Docker via systemd
  • recipe[docker::sysv] Installs/Starts Docker via SysV
  • recipe[docker::upstart] Installs/Starts Docker via Upstart

LWRPs

  • docker_container: container operations
  • docker_image: image/repository operations
  • docker_registry: registry operations

Getting Started

Here's a quick example of pulling the latest image and running a container with exposed ports (creates service automatically):

# Pull latest imagedocker_image'samalba/docker-registry'# Run container exposing portsdocker_container'samalba/docker-registry'dodetachtrueport'5000:5000'env'SETTINGS_FLAVOR=local'volume'/mnt/docker:/docker-storage'end

Maybe you want to automatically update your private registry with changes from your container?

# Login to private registrydocker_registry'https://docker-registry.example.com/'dousername'shipper'password'iloveshipping'end# Pull tagged imagedocker_image'apps/crowsnest'dotag'not-latest'end# Run containerdocker_container'crowsnest'# Save current timestamptimestamp=Time.new.strftime('%Y%m%d%H%M')# Commit container changesdocker_container'crowsnest'dorepository'apps'tagtimestampaction:commitend# Push imagedocker_image'crowsnest'dorepository'apps'tagtimestampaction:pushend

See full documentation for each LWRP and action below for more information.

docker_container

Below are the available actions for the LWRP, default being run.

These attributes are associated with all LWRP actions.

AttributeDescriptionTypeDefault
cmd_timeoutTimeout for docker commands (catchable exception: Chef::Provider::Docker::Container::CommandTimeout)Integernode['docker']['container_cmd_timeout']
commandCommand to run in or identify containerStringnil
container_nameName for container/serviceStringnil

docker_container action :commit

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
authorAuthor for commitStringnil
messageMessage for commitStringnil
repositoryRemote repositoryStringnil
runConfiguration to be applied when the image is launched with docker runStringnil
tagSpecific tag for imageStringnil

Commit a container with optional repository, run specification, and tag:

docker_container'myApp'dorepository'myRepo'tagTime.new.strftime("%Y%m%d%H%M")run'{"Cmd": ["cat", "/world"], "PortSpecs": ["22"]}'action:commitend

docker_container action :cp

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
destinationHost path to copy fileStringnil
sourceContainer path to get fileStringnil

Copying a file from container to host:

docker_container'myApp'dosource'/path/to/container/file'destination'/path/to/save/on/host'action:cpend

docker_container action :export

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
destinationHost path to save tarballStringnil

Exporting container to host:

docker_container'myApp'dodestination'/path/to/save/on/host.tgz'action:exportend

docker_container action :kill

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
cookbookCookbook to grab any templatesStringdocker
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
signalSignal to send to the containerStringnil (implicitly KILL)
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil

Kill a running container:

docker_container'shipyard'doaction:killend

Send SIGQUIT to a running container:

docker_container'shipyard'dosignal'QUIT'action:killend

docker_container action :redeploy

Stops, removes, and runs a container. Useful for notifications from image build/pull.

Attributes for this action can be found in the stop, remove, and run actions.

Redeploy container when new image is pulled:

docker_image'shipyard/shipyard'doaction:pullnotifies:redeploy,'docker_container[shipyard]',:immediatelyenddocker_container'shipyard'do# Other attributesaction:runend

docker_container action :remove

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
cookbookCookbook to grab any templatesStringdocker
forceForce removalTrueClass, FalseClassnil
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil

Remove a container:

docker_container'shipyard'doaction:removeend

docker_container action :remove_link

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
linkLink to remove from containerStringnil

Remove a container:

docker_container'shipyard'dolink'foo'action:remove_linkend

docker_container action :remove_volume

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
volumeVolume(s) to remove from containerString, Arraynil

Remove a container:

docker_container'shipyard'dovolume%w(/extravol1/extravol2)action:remove_volumeend

docker_container action :restart

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
cookbookCookbook to grab any templatesStringdocker
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil

Restart a container:

docker_container'shipyard'doaction:restartend

docker_container action :run

By default, this will handle creating a service for the container when action is run or start. set['docker']['container_init_type'] = false or add init_type false for LWRP to disable this behavior.

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
attachAttach container's stdout/stderr and forward all signals to the processTrueClass, FalseClassnil
cidfileFile to store container IDStringnil
container_nameName for container/serviceStringnil
cookbookCookbook to grab any templatesStringdocker
cpu_sharesCPU shares for containerFixnumnil
detachDetach from container when startingTrueClass, FalseClassnil
dnsDNS servers for containerString, Arraynil
dns_searchDNS search domains for containerString, Arraynil
entrypointOverwrite the default entrypoint set by the imageStringnil
envEnvironment variables to pass to containerString, Arraynil
env_fileRead in a line delimited file of ENV variablesStringnil
exposeExpose a port from the container without publishing it to your hostFixnum, String, Arraynil
hostnameContainer hostnameStringnil
imageImage for containerStringLWRP name
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
linkAdd link to another containerString, Arraynil
labelOptions to pass to underlying labeling systemStringnil
lxc_confCustom LXC optionsString, Arraynil
memorySet memory limit for containerFixnumnil
netConfigure networking for containerStringnil
networking (DEPRECATED)Configure networking for containerTrueClass, FalseClasstrue
optCustom driver optionsString, Arraynil
portMap network port(s) to the containerFixnum (DEPRECATED), String, Arraynil
privilegedGive extended privilegesTrueClass, FalseClassnil
public_port (DEPRECATED)Map host port to containerFixnumnil
publish_exposed_portsPublish all exposed ports to the host interfacesTrueClass, FalseClassfalse
remove_automaticallyAutomatically remove the container when it exits (incompatible with detach)TrueClass, FalseClassfalse
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil
stdinAttach container's stdinTrueClass, FalseClassnil
ttyAllocate a pseudo-ttyTrueClass, FalseClassnil
userUser to run containerStringnil
volumeCreate bind mount(s) with: [host-dir]:[container-dir]:[rwro]. If "container-dir" is missing, then docker creates a new volume.String, Array
volumes_fromMount all volumes from the given container(s)Stringnil
working_directoryWorking directory inside the containerStringnil

Run a container:

docker_container'myImage'dodetachtrueend

Run a container via command:

docker_container'busybox'docommand'sleep 9999'detachtrueend

Run a container from image (docker-registry for example):

docker_container'docker-registry'doimage'samalba/docker-registry'detachtruehostname'docker-registry.example.com'port'5000:5000'env'SETTINGS_FLAVOR=local'volume'/mnt/docker:/docker-storage'end

docker_container action :start

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
attachAttach container's stdout/stderr and forward all signals to the cookbookCookbook to grab any templatesString
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil
stdinAttach container's stdinTrueClass, FalseClassnil

Start a stopped container:

docker_container'shipyard'doaction:startend

docker_container action :stop

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
cookbookCookbook to grab any templatesStringdocker
init_typeInit type for container service handlingFalseClass, Stringnode['docker']['container_init_type']
init_templateTemplate to use for init configurationStringnil
socket_templateTemplate to use for configuring socket (relevent for init_type systemd only)Stringnil

Stop a running container:

docker_container'shipyard'doaction:stopend

docker_container action :wait

Wait for a container to finish:

docker_container'busybox'docommand'sleep 9999'action:waitend

docker_image

Below are the available actions for the LWRP, default being pull.

These attributes are associated with all LWRP actions.

AttributeDescriptionTypeDefault
cmd_timeoutTimeout for docker commands (catchable exception: Chef::Provider::Docker::Image::CommandTimeout)Integernode['docker']['image_cmd_timeout']

docker_image action :build and :build_if_missing

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
dockerfile (DEPRECATED)Dockerfile to build imageStringnil
image_url (DEPRECATED)URL to grab imageStringnil
no_cacheDo not use the cache when building the imageTrueClass, FalseClassfalse
path (DEPRECATED)Local path to filesStringnil
rmRemove intermediate containers after a successful buildTrueClass, FalseClassfalse
sourceSource dockerfile/directory/URL to buildStringnil
tagOptional tag for imageStringnil

Build image from Dockerfile:

docker_image'myImage'dotag'myTag'source'myImageDockerfile'action:build_if_missingend

Build image from remote repository:

docker_image'myImage'dosource'example.com/foo/myImage'tag'myTag'action:build_if_missingend

Conditionally rebuild image if changes upstream:

git"#{Chef::Config[:file_cache_path]}/docker-testcontainerd"dorepository'[email protected]:bflad/docker-testcontainerd.git'notifies:build,'docker_image[bflad/testcontainerd]',:immediatelyenddocker_image'bflad/testcontainerd'doaction:pull_if_missingend

docker_image action :import

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
image_url (DEPRECATED)URL to grab imageStringnil
repositoryOptional repositoryStringnil
sourceSource file/directory/URLStringnil
tagOptional tag for imageStringnil

Import image from local directory:

docker_image'test'dosource'/path/to/test'action:importend

Import image from local file:

docker_image'test'dosource'/path/to/test.tgz'action:importend

Import image from remote URL:

docker_image'test'dosource'https://example.com/testimage.tgz'action:importend

docker_image action :insert

ACTION DEPRECATED AS OF DOCKER 0.10.0

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
destinationDestination path/URLStringnil
sourceSource path/URLStringnil

Insert file from remote URL:

docker_image'test'dosource'http://example.com/some/file.txt'destination'/container/path/for/some/file.txt'action:insertend

docker_image action :load

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
inputImage source (via tar archive file)Stringnil
sourceImage source (via stdin)Stringnil

Load repository via input:

docker_image'test'doinput'/path/to/test.tar'action:loadend

Load repository via stdin:

docker_image'test'dosource'/path/to/test.tgz'action:loadend

docker_image action :pull and :pull_if_missing

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
registryOptional registry serverStringnil
tagOptional tag for imageStringnil

Pull latest image every Chef run:

docker_image'busybox'

Pull latest image only if missing:

docker_image'busybox'doaction:pull_if_missingend

Pull tagged image:

docker_image'bflad/test'dotag'not-latest'end

docker_image action :push

Push image (after logging in with docker_registry):

docker_image'bflad/test'doaction:pushend

docker_image action :remove

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
forceForce removalTrueClass, FalseClassnil
no_pruneDo not delete untagged parentsTrueClass, FalseClassnil

Remove image:

docker_image'busybox'doaction:removeend

docker_image action :save

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
destinationDestination path (via stdout)Stringnil
outputDestination path (via file)Stringnil
tagSave specific tagStringnil

Save repository via file to path:

docker_image'test'dodestination'/path/to/test.tar'action:saveend

Save repository via stdout to path:

docker_image'test'dodestination'/path/to/test.tgz'action:saveend

docker_image action :tag

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
forceForce operationBooleanfalse
repositoryRemote repositoryStringnil
tagSpecific tag for imageStringnil

Tag image:

docker_image'test'dorepository'bflad'tag'1.0.0'action:tagend

docker_registry

These attributes are associated with all LWRP actions.

AttributeDescriptionTypeDefault
cmd_timeoutTimeout for docker commands (catchable exception: Chef::Provider::Docker::Registry::CommandTimeout)Integernode['docker']['registry_cmd_timeout']

docker_registry action :login

These attributes are associated with this LWRP action.

AttributeDescriptionTypeDefault
emailRegistry emailStringnil
passwordRegistry passwordStringnil
usernameRegistry usernameStringnil

Log into or register with public registry:

docker_registry 'https://index.docker.io/v1/' do email '[email protected]' username 'publicme' password 'hope_this_is_in_encrypted_databag' end 

Log into private registry with optional port:

docker_registry 'https://docker-registry.example.com:8443/' do username 'privateme' password 'still_hope_this_is_in_encrypted_databag' end 

Testing and Development

  • Quickly testing with Vagrant: VAGRANT.md
  • Full development and testing workflow with Test Kitchen and friends: TESTING.md

Contributing

Please see contributing information in: CONTRIBUTING.md

Maintainers

License

Please see licensing information in: LICENSE

About

Chef Cookbook for Docker

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published