2015-06-07 23:07:20 -04:00
|
|
|
<!--[metadata]>
|
|
|
|
+++
|
2016-01-23 23:36:40 -05:00
|
|
|
aliases = ["/engine/articles/chef/"]
|
2015-06-07 23:07:20 -04:00
|
|
|
title = "Using Chef"
|
|
|
|
description = "Installation and using Docker via Chef"
|
|
|
|
keywords = ["chef, installation, usage, docker, documentation"]
|
|
|
|
[menu.main]
|
2016-01-23 23:36:40 -05:00
|
|
|
parent = "engine_admin"
|
2016-07-19 00:40:07 -04:00
|
|
|
weight="11"
|
2015-06-07 23:07:20 -04:00
|
|
|
+++
|
|
|
|
<![end-metadata]-->
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
# Using Chef
|
|
|
|
|
2014-04-18 16:21:55 -04:00
|
|
|
> **Note**:
|
2015-10-22 17:49:25 -04:00
|
|
|
> Please note this is a community contributed installation path.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
2014-04-23 16:48:28 -04:00
|
|
|
To use this guide you'll need a working installation of
|
2015-11-24 10:32:43 -05:00
|
|
|
[Chef](https://www.chef.io/). This cookbook supports a variety of
|
2014-04-15 20:53:12 -04:00
|
|
|
operating systems.
|
|
|
|
|
|
|
|
## Installation
|
|
|
|
|
2015-10-22 17:49:25 -04:00
|
|
|
The cookbook is available on the [Chef Supermarket](https://supermarket.chef.io/cookbooks/docker) and can be
|
2014-05-14 13:22:49 -04:00
|
|
|
installed using your favorite cookbook dependency manager.
|
2014-04-15 20:53:12 -04:00
|
|
|
|
|
|
|
The source can be found on
|
2015-10-22 17:49:25 -04:00
|
|
|
[GitHub](https://github.com/someara/chef-docker).
|
|
|
|
|
|
|
|
Usage
|
|
|
|
-----
|
|
|
|
- Add ```depends 'docker', '~> 2.0'``` to your cookbook's metadata.rb
|
|
|
|
- Use resources shipped in cookbook in a recipe, the same way you'd
|
|
|
|
use core Chef resources (file, template, directory, package, etc).
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
docker_service 'default' do
|
|
|
|
action [:create, :start]
|
|
|
|
end
|
|
|
|
|
|
|
|
docker_image 'busybox' do
|
|
|
|
action :pull
|
|
|
|
end
|
|
|
|
|
|
|
|
docker_container 'an echo server' do
|
|
|
|
repo 'busybox'
|
|
|
|
port '1234:1234'
|
|
|
|
command "nc -ll -p 1234 -e /bin/cat"
|
|
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
## Getting Started
|
|
|
|
Here's a quick example of pulling the latest image and running a
|
|
|
|
container with exposed ports.
|
|
|
|
|
|
|
|
```ruby
|
|
|
|
# Pull latest image
|
|
|
|
docker_image 'nginx' do
|
|
|
|
tag 'latest'
|
|
|
|
action :pull
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run container exposing ports
|
|
|
|
docker_container 'my_nginx' do
|
|
|
|
repo 'nginx'
|
|
|
|
tag 'latest'
|
|
|
|
port '80:80'
|
|
|
|
binds [ '/some/local/files/:/etc/nginx/conf.d' ]
|
|
|
|
host_name 'www'
|
|
|
|
domain_name 'computers.biz'
|
|
|
|
env 'FOO=bar'
|
|
|
|
subscribes :redeploy, 'docker_image[nginx]'
|
|
|
|
end
|
|
|
|
```
|