diff --git a/plugins/providers/docker/action/build.rb b/plugins/providers/docker/action/build.rb index 975ce0263..87e27872c 100644 --- a/plugins/providers/docker/action/build.rb +++ b/plugins/providers/docker/action/build.rb @@ -25,6 +25,12 @@ module VagrantPlugins image = image_file.read.chomp end + # Verify the image exists if we have one + if image && !machine.provider.driver.image?(image) + machine.ui.output(I18n.t("docker_provider.build_image_invalid")) + image = nil + end + # If we have no image or we're rebuilding, we rebuild if !image || env[:build_rebuild] # Build it diff --git a/plugins/providers/docker/driver.rb b/plugins/providers/docker/driver.rb index 58c2c1f23..415b40aaf 100644 --- a/plugins/providers/docker/driver.rb +++ b/plugins/providers/docker/driver.rb @@ -63,6 +63,11 @@ module VagrantPlugins result =~ /^#{Regexp.escape cid}$/ end + def image?(id) + result = execute('docker', 'images', '-q').to_s + result =~ /^#{Regexp.escape(id)}$/ + end + def running?(cid) result = execute('docker', 'ps', '-q', '--no-trunc') result =~ /^#{Regexp.escape cid}$/m diff --git a/templates/locales/providers_docker.yml b/templates/locales/providers_docker.yml index 4ef60ae57..b4e27565f 100644 --- a/templates/locales/providers_docker.yml +++ b/templates/locales/providers_docker.yml @@ -4,6 +4,8 @@ en: Image is already built from the Dockerfile. `vagrant reload` to rebuild. build_image_destroy: |- Removing built image... + build_image_invalid: |- + Build image no longer exists. Rebuilding... building: |- Building the container from a Dockerfile... creating: |-