Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boot2docker #2

Merged
merged 3 commits into from
Jul 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ knife-docker bootstraps your Docker containers via SSH. Thus, you need to use a
# Create and bootstrap a Debian container over ssh
$ knife docker create -I knife-docker-debian

# If using boot2docker (i.e. running docker + knife under os x)
$ knife docker create -I knife-docker-debian -b

# Create a Debian container, bootstrap it, and apply the specified roles/recipes
$ knife docker create -I knife-docker-debian -r 'recipe[postgresql::server]'

Expand Down
23 changes: 19 additions & 4 deletions lib/chef/knife/docker_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DockerCreate < Chef::Knife
end

banner "knife docker create (options)"

option :_image,
:short => "-I IMAGE",
:long => "--image IMAGE",
Expand Down Expand Up @@ -78,6 +78,13 @@ class DockerCreate < Chef::Knife
:long => "--identity IDENTITY_FILE",
:description => "SSH identity file for authentication"

option :boot2docker,
:short => "-b",
:long => "--boot2docker",
:boolean => true,
:default => false,
:description => "Set if using boot2docker"

def locate_config_value(key)
key = key.to_sym
config[key] || Chef::Config[:knife][key]
Expand All @@ -98,9 +105,17 @@ def run
exit 1
end

# get container IP
container_info = `docker inspect #{id}`
ip = container_info.match(/"IPAddress": "([\d\.]+)"/)[1]
# if using boot2docker, get server ip and forwarded container ssh port
if config[:boot2docker]
boot2docker_ip = `boot2docker ip 2>/dev/null`
ip = boot2docker_ip.match(/([\d\.]+)/)[1]
container_info = `docker inspect #{id}`
config[:ssh_port] = container_info.match(/"HostPort": "(\d+)"/)[1]
else
# get container IP
container_info = `docker inspect #{id}`
ip = container_info.match(/"IPAddress": "([\d\.]+)"/)[1]
end

# containers boot *very* fast, but it might happen that we try to
# bootstrap before SSH is up. Let's wait a second.
Expand Down
2 changes: 1 addition & 1 deletion lib/knife-docker/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Knife
module Docker
VERSION = "0.0.2"
VERSION = "0.0.3"
MAJOR, MINOR, TINY = VERSION.split('.')
end
end