The Docker Compose Cookbook is a library cookbook that provides custom resources for use in recipes.
- Working Docker installation. You might want to use the excellent docker Cookbook to provision Docker.
Place a dependency on the docker-compose cookbook in your cookbook's metadata.rb
depends 'docker_compose', '~> 0.0'
Create a Docker Compose file for the application you want to provision. A simple Compose file that uses the official nginx Docker image looks like this:
version: '2'
services:
web_server:
image: nginx
ports:
- "80:80"
Then, in a recipe:
include_recipe 'docker_compose::installation'
# Provision Compose file
cookbook_file '/etc/docker-compose_nginx.yml' do
source 'docker-compose_nginx.yml'
owner 'root'
group 'root'
mode 0640
notifies :up, 'docker_compose_application[nginx]', :delayed
end
# Provision Compose application
docker_compose_application 'nginx' do
action :up
compose_files [ '/etc/docker-compose_nginx.yml' ]
end
-
node['docker_compose']['release']
- The release version of Docker Compose to install. Defaults to a sane, current default. -
node['docker_compose']['command_path']
- The path under which thedocker-compose
command should be installed. Defaults to/usr/local/bin/docker-compose
The default
recipe is simply an alias for the installation
recipe.
The installation
recipe installs the docker-compose
binary by downloading
it from the vendor's servers, as described in the
official Docker Compose documentation.
The path to which the docker-compose
command is installed can be configured
via the node['docker_compose']['command_path']
attribute.
The docker_compose_application
provisions a Docker application (that usually
consists of several services) using a Docker Compose file.
docker_compose_application 'nginx' do
action :up
compose_files [ '/etc/docker-compose_nginx.yml', '/etc/docker-compose_nginx.additional.yml' ]
services ['nginx']
remove_orphans true
end
-
project_name
- A string to identify the Docker Compose application. Defaults to the resource name. -
compose_files
- The list of Compose files that makes up the Docker Compose application. The specified file names are passed to thedocker-compose
command in the order in which they appear in the list. -
services
- The list of services to start or stop. Defaults to all services that are specified in the Compose files. -
remove_orphans
- Remove containers for services not defined in the Compose file.
-
:up
- Create and start containers. Equivalent to callingdocker-compose up -d --build
with the Compose files that were specified using thecompose_files
parameter. -
:down
- Stop and remove containers and networks. Equivalent to callingdocker-compose down
with the Compose files that were specified using thecompose_files
parameter. -
:restart
- Calls down and up actions. Useful for notications from changes to Dockerfiles and Compose files. -
:create
- Create containers for a service. Equivalent to callingdocker-compose create
with the Compose files that were specified using thecompose_files
parameter.
- Sebastian Boschert ([email protected])
Copyright (c) 2016 Sebastian Boschert.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.