Skip to content
This repository was archived by the owner on Jul 6, 2018. It is now read-only.

Commit

Permalink
Merge pull request #33 from marc-/volumes
Browse files Browse the repository at this point in the history
Added volumes support #29
  • Loading branch information
tyler-ball committed May 5, 2015
2 parents ebbce5a + 771794e commit 54d90f6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ machine 'wario' do
"deep" => 'purple',
"led" => 'zeppelin'
}

# Ports can be one of two forms:
# src_port (string or integer) is a pass-through, i.e 8022 or "9933"
# src:dst (string) is a map from src to dst, i.e "8022:8023" maps 8022 externally to 8023 in the container
Expand All @@ -46,6 +46,17 @@ machine 'wario' do
:ports => 1234
:ports => "2345:6789"

# Volumes can be one of three forms:
# src_volume (string) is volume to add to container, i.e. creates new volume inside container at "/tmp"
# src:dst (string) mounts host's directory src to container's dst, i.e "/tmp:/tmp1" mounts host's directory /tmp to container's /tmp1
# src:dst:mode (string) mounts host's directory src to container's dst with the specified mount option, i.e "/:/rootfs:ro" mounts read-only host's root (/) folder to container's /rootfs

# Example (single):
:volumes => "/tmp"

# Example (multiple):
:volumes => ["/tmp:/tmp", "/:/rootfs:ro"]

# if you need to keep stdin open (i.e docker run -i)
# :keep_stdin_open => true

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def initialize(machine_spec, transport, convergence_strategy, opts = {})
@env = opts[:env]
@command = opts[:command]
@ports = opts[:ports]
@volumes = opts[:volumes]
@keep_stdin_open = opts[:keep_stdin_open]
@container_name = machine_spec.location['container_name']
@transport = transport
Expand All @@ -27,7 +28,7 @@ def converge(action_handler)
super action_handler
if @command
Chef::Log.debug("DockerContainerMachine converge complete, executing #{@command} in #{@container_name}")
@transport.execute(@command, :env => @env ,:detached => true, :read_only => true, :ports => @ports, :keep_stdin_open => @keep_stdin_open)
@transport.execute(@command, :env => @env ,:detached => true, :read_only => true, :ports => @ports, :volumes => @volumes, :keep_stdin_open => @keep_stdin_open)
end
end

Expand Down
7 changes: 7 additions & 0 deletions lib/chef/provisioning/docker_driver/docker_transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,13 @@ def execute(command, options={})
end
end

if options[:volumes]
options[:volumes].each do |volume|
args << '-v'
args << "#{volume}"
end
end

if options[:keep_stdin_open]
args << '-i'
end
Expand Down
1 change: 1 addition & 0 deletions lib/chef/provisioning/docker_driver/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ def machine_for(machine_spec, machine_options, base_image_name)
:command => docker_options[:command],
:env => docker_options[:env],
:ports => [].push(docker_options[:ports]).flatten,
:volumes => [].push(docker_options[:volumes]).flatten.compact,
:keep_stdin_open => docker_options[:keep_stdin_open]
)
end
Expand Down

0 comments on commit 54d90f6

Please # to comment.