diff --git a/lib/vagrant/util/ssh.rb b/lib/vagrant/util/ssh.rb index 487b972b0..681c8ad20 100644 --- a/lib/vagrant/util/ssh.rb +++ b/lib/vagrant/util/ssh.rb @@ -165,11 +165,6 @@ module Vagrant # If we're still here, it means we're supposed to subprocess # out to ssh rather than exec it. - # - # There is a lot of special-case code for Windows below. Windows - # has a bug with creating a TTY file handle for stdin so SSH doesn't - # work well. We simulate it by copying stdin over. It isn't ideal, - # but it kind of works. LOGGER.info("Executing SSH in subprocess: #{command_options.inspect}") process = ChildProcess.build("ssh", *command_options) process.io.inherit! diff --git a/plugins/providers/docker/action/create.rb b/plugins/providers/docker/action/create.rb index 3068d3b58..c65ebdf18 100644 --- a/plugins/providers/docker/action/create.rb +++ b/plugins/providers/docker/action/create.rb @@ -58,10 +58,20 @@ module VagrantPlugins elsif params[:detach] env[:ui].detail(" \n"+I18n.t("docker_provider.running_detached")) else + ui_opts = {} + + # If we're running with a pty, we want the output to look as + # authentic as possible. We don't prefix things and we don't + # output a newline. + if env[:run_pty] + ui_opts[:prefix] = false + ui_opts[:new_line] = false + end + # For run commands, we run it and stream back the output env[:ui].detail(" \n"+I18n.t("docker_provider.running")+"\n ") - @driver.create(params) do |type, data| - env[:ui].detail(data.chomp) + @driver.create(params, stdin: env[:run_pty]) do |type, data| + env[:ui].detail(data.chomp, **ui_opts) end end diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 3661b5522..4f4a4e7fc 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -25,7 +25,7 @@ module VagrantPlugins match[1] end - def create(params, &block) + def create(params, **opts, &block) image = params.fetch(:image) links = params.fetch(:links) ports = Array(params[:ports]) @@ -44,11 +44,11 @@ module VagrantPlugins run_cmd += volumes.map { |v| ['-v', v.to_s] } run_cmd += %W(--privileged) if params[:privileged] run_cmd += %W(-h #{params[:hostname]}) if params[:hostname] - run_cmd << "-t" if params[:pty] + run_cmd << "-i" << "-t" if params[:pty] run_cmd += params[:extra_args] if params[:extra_args] run_cmd += [image, cmd] - execute(*run_cmd.flatten, &block).chomp + execute(*run_cmd.flatten, **opts, &block).chomp end def state(cid) @@ -131,8 +131,8 @@ module VagrantPlugins end end - def execute(*cmd, &block) - @executor.execute(*cmd, &block) + def execute(*cmd, **opts, &block) + @executor.execute(*cmd, **opts, &block) end end end diff --git a/plugins/providers/docker/executor/local.rb b/plugins/providers/docker/executor/local.rb index 5393a868a..61b633bc5 100644 --- a/plugins/providers/docker/executor/local.rb +++ b/plugins/providers/docker/executor/local.rb @@ -7,7 +7,7 @@ module VagrantPlugins # The Local executor executes a Docker client that is running # locally. class Local - def execute(*cmd, &block) + def execute(*cmd, **opts, &block) # Append in the options for subprocess cmd << { :notify => [:stdout, :stderr] } diff --git a/plugins/providers/docker/executor/vagrant.rb b/plugins/providers/docker/executor/vagrant.rb index 85f274614..c25af2006 100644 --- a/plugins/providers/docker/executor/vagrant.rb +++ b/plugins/providers/docker/executor/vagrant.rb @@ -10,12 +10,15 @@ module VagrantPlugins @host_machine = host_machine end - def execute(*cmd, &block) + def execute(*cmd, **opts, &block) quote = '"' cmd = cmd.map do |a| "#{quote}#{::Vagrant::Util::ShellQuote.escape(a, quote)}#{quote}" end.join(" ") + # If we want stdin, we just run in a full subprocess + return ssh_run(cmd) if opts[:stdin] + # Add a start fence so we know when to start reading output. # We have to do this because boot2docker outputs a login shell # boot2docker version that we get otherwise and messes up output. @@ -61,6 +64,17 @@ module VagrantPlugins stdout.chomp end + + protected + + def ssh_run(cmd) + @host_machine.action( + :ssh_run, + ssh_run_command: cmd, + ) + + "" + end end end end