Restart docker container if newer image build is available.

This commit is contained in:
Luca Invernizzi 2015-11-24 16:01:21 -08:00 committed by Seth Vargo
parent 8190fba872
commit d8c56be510
No known key found for this signature in database
GPG Key ID: 905A90C2949E8787
1 changed files with 15 additions and 1 deletions

View File

@ -59,7 +59,8 @@ module VagrantPlugins
id = "$(cat #{config[:cidfile]})"
if container_exists?(id)
if container_args_changed?(config)
if container_args_changed?(config) or container_img_changed?(config)
@machine.ui.info(I18n.t("vagrant.docker_restarting_container",
name: config[:name],
))
@ -94,6 +95,19 @@ module VagrantPlugins
lookup_container(id)
end
def container_img_changed?(config)
# Returns true if there is a container running with the given :name,
# and the container is not using the latest :image.
# Here, "docker inspect <container>" returns the id of the image
# that the container is using. We check that the latest image that
# has been built with that name (:image) matches the one that the
# container is running.
cmd = ("docker inspect --format='{{.Image}}' #{config[:name]} |" +
" grep $(docker images -q #{config[:image]})")
return !@machine.communicate.test(cmd)
end
def container_args_changed?(config)
path = container_data_path(config)
return true if !path.exist?