diff --git a/lib/hoosegow/docker.rb b/lib/hoosegow/docker.rb index 7bef80e..fc435ae 100644 --- a/lib/hoosegow/docker.rb +++ b/lib/hoosegow/docker.rb @@ -80,9 +80,11 @@ def run_container(image, data, &block) # Returns nothing. def create_container(image) @container = ::Docker::Container.create @container_options.merge( - :StdinOnce => true, - :OpenStdin => true, - :Volumes => volumes_for_create, + :StdinOnce => true, + :OpenStdin => true, + :HostConfig => { + :Binds => volumes_for_bind + }, :Image => image ) callback @after_create @@ -92,7 +94,7 @@ def create_container(image) # # Returns nothing. def start_container - @container.start :Binds => volumes_for_bind + @container.start callback @after_start end @@ -200,19 +202,7 @@ def docker_url(options) end end - # Private: Generate the `Volumes` argument for creating a container. - # - # Given a hash of container_path => local_path in @volumes, generate a - # hash of container_path => {}. - def volumes_for_create - result = {} - each_volume do |container_path, local_path, permissions| - result[container_path] = {} - end - result - end - - # Private: Generate the `Binds` argument for starting a container. + # Private: Generate the `Binds` argument for creating a container. # # Given a hash of container_path => local_path in @volumes, generate an # array of "local_path:container_path:rw". diff --git a/spec/hoosegow_docker_spec.rb b/spec/hoosegow_docker_spec.rb index 320a5e7..692ad31 100644 --- a/spec/hoosegow_docker_spec.rb +++ b/spec/hoosegow_docker_spec.rb @@ -1,3 +1,4 @@ +require 'fileutils' require_relative '../lib/hoosegow' unless defined?(CONFIG) @@ -18,13 +19,11 @@ context 'unspecified' do subject { described_class.new } - its(:volumes_for_create) { should be_empty } its(:volumes_for_bind) { should be_empty } end context 'empty' do let(:volumes) { {} } - its(:volumes_for_create) { should be_empty } its(:volumes_for_bind) { should be_empty } end @@ -33,10 +32,6 @@ "/inside/path" => "/home/burke/data-for-container:rw", "/other/path" => "/etc/shared-config", } } - its(:volumes_for_create) { should == { - "/inside/path" => {}, - "/other/path" => {}, - } } its(:volumes_for_bind) { should == [ "/home/burke/data-for-container:/inside/path:rw", "/etc/shared-config:/other/path:ro", @@ -44,6 +39,32 @@ end end + context "volume is writable" do + it "calls after_create" do + test_dir = File.join(Dir.pwd, 'volume-test') + FileUtils.remove_dir(test_dir, true) + FileUtils.mkpath(test_dir) + + config = CONFIG.merge( + :Entrypoint => ['/usr/bin/touch', '/volume-test/test'], + :volumes => { '/volume-test' => test_dir + ":rw"} + ) + docker = Hoosegow::Docker.new(config) + begin + docker.create_container CONFIG[:image_name] + docker.start_container + ensure + docker.stop_container + docker.delete_container + end + + exists = File.exists?(File.join(test_dir, 'test')) + expect(exists).to be_truthy + FileUtils.remove_dir(test_dir, true) + end + end + + context 'docker_url' do it "correctly generates TCP urls" do hoosegow = Hoosegow::Docker.new CONFIG.merge(:host => "1.1.1.1", :port => 1234)