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

Commit 771794e

Browse files
committed
Added volumes support #29
Signed-off-by: Maksim Chizhov <maksim.chizhov@gmail.com>
1 parent ebbce5a commit 771794e

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

README.md

+12-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ machine 'wario' do
3434
"deep" => 'purple',
3535
"led" => 'zeppelin'
3636
}
37-
37+
3838
# Ports can be one of two forms:
3939
# src_port (string or integer) is a pass-through, i.e 8022 or "9933"
4040
# src:dst (string) is a map from src to dst, i.e "8022:8023" maps 8022 externally to 8023 in the container
@@ -46,6 +46,17 @@ machine 'wario' do
4646
:ports => 1234
4747
:ports => "2345:6789"
4848

49+
# Volumes can be one of three forms:
50+
# src_volume (string) is volume to add to container, i.e. creates new volume inside container at "/tmp"
51+
# 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
52+
# 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
53+
54+
# Example (single):
55+
:volumes => "/tmp"
56+
57+
# Example (multiple):
58+
:volumes => ["/tmp:/tmp", "/:/rootfs:ro"]
59+
4960
# if you need to keep stdin open (i.e docker run -i)
5061
# :keep_stdin_open => true
5162

lib/chef/provisioning/docker_driver/docker_container_machine.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def initialize(machine_spec, transport, convergence_strategy, opts = {})
1414
@env = opts[:env]
1515
@command = opts[:command]
1616
@ports = opts[:ports]
17+
@volumes = opts[:volumes]
1718
@keep_stdin_open = opts[:keep_stdin_open]
1819
@container_name = machine_spec.location['container_name']
1920
@transport = transport
@@ -27,7 +28,7 @@ def converge(action_handler)
2728
super action_handler
2829
if @command
2930
Chef::Log.debug("DockerContainerMachine converge complete, executing #{@command} in #{@container_name}")
30-
@transport.execute(@command, :env => @env ,:detached => true, :read_only => true, :ports => @ports, :keep_stdin_open => @keep_stdin_open)
31+
@transport.execute(@command, :env => @env ,:detached => true, :read_only => true, :ports => @ports, :volumes => @volumes, :keep_stdin_open => @keep_stdin_open)
3132
end
3233
end
3334

lib/chef/provisioning/docker_driver/docker_transport.rb

+7
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ def execute(command, options={})
8181
end
8282
end
8383

84+
if options[:volumes]
85+
options[:volumes].each do |volume|
86+
args << '-v'
87+
args << "#{volume}"
88+
end
89+
end
90+
8491
if options[:keep_stdin_open]
8592
args << '-i'
8693
end

lib/chef/provisioning/docker_driver/driver.rb

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ def machine_for(machine_spec, machine_options, base_image_name)
227227
:command => docker_options[:command],
228228
:env => docker_options[:env],
229229
:ports => [].push(docker_options[:ports]).flatten,
230+
:volumes => [].push(docker_options[:volumes]).flatten.compact,
230231
:keep_stdin_open => docker_options[:keep_stdin_open]
231232
)
232233
end

0 commit comments

Comments
 (0)