providers/docker: rebuild image if it doesn't exist

This commit is contained in:
Mitchell Hashimoto 2014-04-20 08:24:43 -07:00
parent d837086572
commit 1c3ee6ffa3
3 changed files with 13 additions and 0 deletions

View File

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

View File

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

View File

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