Merge pull request #7358 from mitchellh/sethvargo/pr-6620
Restart container if newer build is available
This commit is contained in:
commit
7301ce5de3
|
@ -60,7 +60,13 @@ module VagrantPlugins
|
|||
|
||||
if container_exists?(id)
|
||||
if container_args_changed?(config)
|
||||
@machine.ui.info(I18n.t("vagrant.docker_restarting_container",
|
||||
@machine.ui.info(I18n.t("vagrant.docker_restarting_container_args",
|
||||
name: config[:name],
|
||||
))
|
||||
stop_container(id)
|
||||
create_container(config)
|
||||
elsif container_image_changed?(config)
|
||||
@machine.ui.info(I18n.t("vagrant.docker_restarting_container_image",
|
||||
name: config[:name],
|
||||
))
|
||||
stop_container(id)
|
||||
|
@ -94,6 +100,19 @@ module VagrantPlugins
|
|||
lookup_container(id)
|
||||
end
|
||||
|
||||
def container_image_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?
|
||||
|
|
|
@ -135,8 +135,10 @@ en:
|
|||
Building Docker images...
|
||||
docker_running: |-
|
||||
-- Container: %{name}
|
||||
docker_restarting_container: |-
|
||||
-- Detected changes to container '%{name}', restarting...
|
||||
docker_restarting_container_args: |-
|
||||
-- Detected changes to container '%{name}' args, restarting...
|
||||
docker_restarting_container_image: |-
|
||||
-- Detected newer image for container '%{name}', restarting...
|
||||
docker_starting_containers: |-
|
||||
Starting Docker containers...
|
||||
inserted_key: |-
|
||||
|
|
Loading…
Reference in New Issue