diff --git a/plugins/providers/docker/action/create.rb b/plugins/providers/docker/action/create.rb index dffd27bfb..6b10dd180 100644 --- a/plugins/providers/docker/action/create.rb +++ b/plugins/providers/docker/action/create.rb @@ -29,6 +29,9 @@ module VagrantPlugins # Allocate a pty if it was requested params[:pty] = true if env[:run_pty] + # Remove container after execution + params[:rm] = true if env[:run_rm] + # We link to our original container # TODO end diff --git a/plugins/providers/docker/command/run.rb b/plugins/providers/docker/command/run.rb index 24ddf2c87..13f23dcdd 100644 --- a/plugins/providers/docker/command/run.rb +++ b/plugins/providers/docker/command/run.rb @@ -10,6 +10,7 @@ module VagrantPlugins options = {} options[:detach] = false options[:pty] = false + options[:rm] = true opts = OptionParser.new do |o| o.banner = "Usage: vagrant docker-run [command...]" @@ -24,6 +25,10 @@ module VagrantPlugins o.on("-t", "--[no-]tty", "Allocate a pty") do |t| options[:pty] = t end + + o.on("-r,", "--[no-]rm", "Remove container after execution") do |r| + options[:rm] = r + end end # Parse out the extra args to send to SSH, which is everything @@ -56,6 +61,7 @@ module VagrantPlugins run_command: command, run_detach: options[:detach], run_pty: options[:pty], + run_rm: options[:rm] ) end diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 987437c1b..00cbec080 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -49,6 +49,7 @@ module VagrantPlugins run_cmd += %W(--privileged) if params[:privileged] run_cmd += %W(-h #{params[:hostname]}) if params[:hostname] run_cmd << "-i" << "-t" if params[:pty] + run_cmd << "--rm=true" if params[:rm] run_cmd += params[:extra_args] if params[:extra_args] run_cmd += [image, cmd]