provider/docker: Separate -i and -t flags for exec

This commit is contained in:
Seth Vargo 2016-05-31 20:04:08 -04:00
parent bf96b3348b
commit cfac24779c
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
2 changed files with 15 additions and 8 deletions

View File

@ -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

View File

@ -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