diff --git a/plugins/providers/docker/command/exec.rb b/plugins/providers/docker/command/exec.rb index ab40fbda7..4172a668d 100644 --- a/plugins/providers/docker/command/exec.rb +++ b/plugins/providers/docker/command/exec.rb @@ -10,6 +10,7 @@ module VagrantPlugins options = {} options[:detach] = false options[:pty] = false + options[:interactive] = false options[:prefix] = true opts = OptionParser.new do |o| @@ -22,6 +23,10 @@ module VagrantPlugins options[:detach] = d end + o.on("-i", "--[no-]interactive", "Keep STDIN open even if not attached") do |i| + options[:interactive] = i + end + o.on("-t", "--[no-]tty", "Allocate a pty") do |t| options[:pty] = t end @@ -58,15 +63,17 @@ module VagrantPlugins @env.ui.info("#{machine.id} is not running.") next end - exec_command(machine, options, command) + exec_command(machine, command, options) end return 0 end - def exec_command(machine, options, command) + def exec_command(machine, command, options) exec_cmd = %w(docker exec) - exec_cmd << "-it" if options[:pty] + exec_cmd << "-i" if options[:interactive] + exec_cmd << "-t" if options[:pty] + exec_cmd << "-u" << options[:user] if options[:user] exec_cmd << machine.id exec_cmd += options[:extra_args] if options[:extra_args] exec_cmd += command diff --git a/website/source/docs/docker/commands.html.md b/website/source/docs/docker/commands.html.md index ac567df55..d282e4281 100644 --- a/website/source/docs/docker/commands.html.md +++ b/website/source/docs/docker/commands.html.md @@ -43,13 +43,13 @@ This Vagrantfile will start the official Docker Consul image. However, the associated Vagrant command to `docker-exec` into this instance is: ```sh -$ vagrant docker-exec -t -- /bin/sh +$ vagrant docker-exec -it -- /bin/sh ``` In particular, the command is actually: ```sh -$ vagrant docker-exec default -t -- /bin/sh +$ vagrant docker-exec default -it -- /bin/sh ``` Because "default" is the default name of the first defined VM. In a @@ -76,13 +76,13 @@ The following command is invalid: ```sh # Not valid -$ vagrant docker-exec -t nginx -- /bin/sh +$ vagrant docker-exec -it nginx -- /bin/sh ``` This is because the "name" of the VM is "web", so the command is actually: ```sh -$ vagrant docker-exec -t web -- /bin/sh +$ vagrant docker-exec -it web -- /bin/sh ``` For this reason, it is recommended that you name the VM the same as the @@ -90,7 +90,7 @@ container. In the above example, it is unambiguous that the command to enter the Consul container is: ```sh -$ vagrant docker-exec -t consul -- /bin/sh +$ vagrant docker-exec -it consul -- /bin/sh ``` ### docker-logs