From b26ecb0150e0247edf7bea67e7b393f83699feab Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 May 2014 21:35:08 -0700 Subject: [PATCH] providers/docker: smarter about setting ID to nil for machine --- plugins/providers/docker/action.rb | 1 + plugins/providers/docker/action/destroy.rb | 25 +++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/plugins/providers/docker/action.rb b/plugins/providers/docker/action.rb index 3c84e9951..e0ed042a3 100644 --- a/plugins/providers/docker/action.rb +++ b/plugins/providers/docker/action.rb @@ -143,6 +143,7 @@ module VagrantPlugins b.use Call, IsState, :not_created do |env, b2| if env[:result] b2.use Message, I18n.t("docker_provider.messages.not_created") + b2.use Destroy next end diff --git a/plugins/providers/docker/action/destroy.rb b/plugins/providers/docker/action/destroy.rb index 37ae14df8..a33c629cd 100644 --- a/plugins/providers/docker/action/destroy.rb +++ b/plugins/providers/docker/action/destroy.rb @@ -7,20 +7,25 @@ module VagrantPlugins end def call(env) - env[:ui].info I18n.t("docker_provider.messages.destroying") - machine = env[:machine] - driver = machine.provider.driver - # If we have a build image, store that - image_file = machine.data_dir.join("docker_build_image") - image = nil - if image_file.file? - image = image_file.read.chomp + # If the container actually exists, destroy it + if machine.state.id != :not_created + driver = machine.provider.driver + + # If we have a build image, store that + image_file = machine.data_dir.join("docker_build_image") + image = nil + if image_file.file? + image = image_file.read.chomp + end + env[:build_image] = image + + env[:ui].info I18n.t("docker_provider.messages.destroying") + driver.rm(machine.id) end - env[:build_image] = image - driver.rm(machine.id) + # Otherwise, always make sure we remove the ID machine.id = nil @app.call(env)