At the time of writing there is not a lot of information about how to set-up Chef with Docker, so I decided to write a short tutorial. The code below shows how to use chef with Docker. This tutorial assumes you have chef and docker installed. The user executing should also be included the Docker group.
$ chef gem install knife-container
$ knife container docker init example1 -r 'recipe[my_cookbook]' -z ... Downloading base image: chef/ubuntu-12.04:latest. This process may take awhile... Tagging base image chef/ubuntu-12.04 as example1 Context Created: /home/ward/cookbooks/dockerfiles/example1 $
Note: Replace my_cookbook with your own cookbook
$ knife container docker build example1 ... Successfully built 39cca130d1f8
$ docker run --name example1_instance1 --publish=127.0.0.1:8080:80 -i -t example1 ... Chef Client finished, 1/4 resources updated in 11.100677039 seconds
This command also exposes port 80 of the Docker container to the host system.
That was it, you just installed knife-container, initialized a Dockerfile and ran the container using knife. Any feedback using the comments below is appreciated!