diff --git a/lib/kitchen/docker/container.rb b/lib/kitchen/docker/container.rb index 83624b6a..2595dfed 100644 --- a/lib/kitchen/docker/container.rb +++ b/lib/kitchen/docker/container.rb @@ -37,13 +37,27 @@ def create(state) end state[:username] = @config[:username] - state[:hostname] = 'localhost' + end + + def destroy(state) + info("[Docker] Destroying Docker container #{state[:container_id]}") if state[:container_id] + remove_container(state) if container_exists?(state) + + if @config[:remove_images] && state[:image_id] + remove_image(state) if image_exists?(state) + end + end + + def hostname(state) + hostname = 'localhost' if remote_socket? - state[:hostname] = socket_uri.host - elsif config[:use_internal_docker_network] - state[:hostname] = container_ip_address(state) + hostname = socket_uri.host + elsif @config[:use_internal_docker_network] + hostname = container_ip_address(state) end + + hostname end def upload(locals, remote) @@ -56,15 +70,6 @@ def upload(locals, remote) files end - - def destroy(state) - info("[Docker] Destroying Docker container #{state[:container_id]}") if state[:container_id] - remove_container(state) if container_exists?(state) - - if @config[:remove_images] && state[:image_id] - remove_image(state) if image_exists?(state) - end - end end end end diff --git a/lib/kitchen/docker/container/linux.rb b/lib/kitchen/docker/container/linux.rb index 5b9d0ef9..2342ea4b 100644 --- a/lib/kitchen/docker/container/linux.rb +++ b/lib/kitchen/docker/container/linux.rb @@ -37,7 +37,7 @@ def create(state) state[:ssh_key] = @config[:private_key] state[:image_id] = build_image(state, dockerfile) unless state[:image_id] state[:container_id] = run_container(state, 22) unless state[:container_id] - state[:hostname] = 'localhost' + state[:hostname] = hostname(state) state[:port] = container_ssh_port(state) end diff --git a/lib/kitchen/docker/container/windows.rb b/lib/kitchen/docker/container/windows.rb index f5c3e5e8..168dca70 100644 --- a/lib/kitchen/docker/container/windows.rb +++ b/lib/kitchen/docker/container/windows.rb @@ -30,6 +30,7 @@ def create(state) state[:username] = @config[:username] state[:image_id] = build_image(state, dockerfile) unless state[:image_id] state[:container_id] = run_container(state) unless state[:container_id] + state[:hostname] = hostname(state) end def execute(command)