From d7ecd99e2ecc211e8e2cc57a7e9f30cdf94ae772 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 28 Apr 2014 09:36:55 -0700 Subject: [PATCH] providers/docker: be more lenient about deleting built image --- plugins/providers/docker/action/destroy_build_image.rb | 5 ++++- plugins/providers/docker/driver.rb | 2 ++ templates/locales/providers_docker.yml | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/plugins/providers/docker/action/destroy_build_image.rb b/plugins/providers/docker/action/destroy_build_image.rb index a5e1b4ad0..897a7f625 100644 --- a/plugins/providers/docker/action/destroy_build_image.rb +++ b/plugins/providers/docker/action/destroy_build_image.rb @@ -26,7 +26,10 @@ module VagrantPlugins if image machine.ui.output(I18n.t("docker_provider.build_image_destroy")) - machine.provider.driver.rmi(image) + if !machine.provider.driver.rmi(image) + machine.ui.detail(I18n.t( + "docker_provider.build_image_destroy_in_use")) + end end if image_file && image_file.file? diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index aa43ca91b..a85f3e559 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -104,7 +104,9 @@ module VagrantPlugins def rmi(id) execute('docker', 'rmi', id) + return true rescue Exception => e + return false if e.to_s.include?("is using it") raise if !e.to_s.include?("No such image") end diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 3652d2c97..5cf2836d6 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -4,6 +4,10 @@ en: Image is already built from the Dockerfile. `vagrant reload` to rebuild. build_image_destroy: |- Removing built image... + build_image_destroy_in_use: |- + Build image couldn't be destroyed because the image is in use. The + image must be destroyed manually in the future if you want to remove + it. build_image_invalid: |- Build image no longer exists. Rebuilding... building: |-