Skip to content

Commit

Permalink
Fixes issues where remove_images fails if the image is in use by anot…
Browse files Browse the repository at this point in the history
…her container.
  • Loading branch information
ersmith committed Dec 19, 2020
1 parent 5d6ba50 commit 441509d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/kitchen/docker/helpers/image_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ def parse_image_id(output)

def remove_image(state)
image_id = state[:image_id]
docker_command("rmi #{image_id}")
if image_in_use?(state)
info("[Docker] Image ID #{image_id} is in use. Skipping removal")
else
info("[Docker] Removing image with Image ID #{image_id}.")
docker_command("rmi #{image_id}")
end
end

def build_image(state, dockerfile)
Expand All @@ -62,6 +67,10 @@ def build_image(state, dockerfile)
def image_exists?(state)
state[:image_id] && !!docker_command("inspect --type=image #{state[:image_id]}") rescue false
end

def image_in_use?(state)
docker_command('ps -a', suppress_output: !logger.debug?).include?(state[:image_id])
end
end
end
end
Expand Down

0 comments on commit 441509d

Please sign in to comment.