Skip to content
This repository was archived by the owner on May 9, 2022. It is now read-only.
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
27 changes: 21 additions & 6 deletions lib/hoosegow/docker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,15 @@ def run_container(image, data, &block)
#
# Returns nothing.
def create_container(image)
create_options = default_container_options(image)

# Merge in additional :HostConfig options into default options
if @container_options.has_key?(:HostConfig)
create_options[:HostConfig].merge!(@container_options[:HostConfig])
end

@container = ::Docker::Container.create @container_options.merge(
:StdinOnce => true,
:OpenStdin => true,
:HostConfig => {
:Binds => volumes_for_bind
},
:Image => image
create_options
)
callback @after_create
end
Expand Down Expand Up @@ -172,6 +174,19 @@ def image_exist?(name)
end

private

# Private: Default options used to create containers
def default_container_options(image)
{
:StdinOnce => true,
:OpenStdin => true,
:HostConfig => {
:Binds => volumes_for_bind
},
:Image => image
}
end

# Private: Set the docker URL, if related options are present.
def set_docker_url!(options)
if url = docker_url(options)
Expand Down
32 changes: 32 additions & 0 deletions spec/hoosegow_docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,38 @@
end
end

context "with custom connection options" do
before(:each) {
FileUtils.remove_dir(test_dir, true)
FileUtils.mkpath(test_dir)
}
after { FileUtils.remove_dir(test_dir, true) }

let(:test_dir) { File.join(Dir.pwd, 'volume-test') }

it "configures ExtraHosts option" do
config = CONFIG.merge(
:Entrypoint => ['/bin/sh', '-c', 'getent hosts some-service > /volume-test/out.txt'],
:volumes => { '/volume-test' => test_dir + ":rw"},
:HostConfig => {
:ExtraHosts => ["some-service:127.0.0.1"]
}
)
docker = Hoosegow::Docker.new(config)
begin
docker.create_container CONFIG[:image_name]
docker.start_container
ensure
docker.stop_container
docker.delete_container
end

# Ensure ExtraHosts config is set
contents = File.read(File.join(test_dir, 'out.txt'))
expect(contents).to match("127.0.0.1\s+some-service")
end
end


context 'docker_url' do
it "correctly generates TCP urls" do
Expand Down