Skip to content

Commit

Permalink
feat: Tell the user when we can't remove the image if it's in use (#406)
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <dan.webb@damacus.io>
Co-authored-by: Edward Smith <edward@ersmith.me>
  • Loading branch information
damacus and ersmith committed Nov 27, 2023
1 parent 90bf689 commit bcb7c2b
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/kitchen/docker/helpers/image_helper.rb
Expand Up @@ -41,7 +41,16 @@ 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 image_in_use?(state)
docker_command("ps -a", suppress_output: !logger.debug?).include?(state[:image_id])
end

def build_image(state, dockerfile)
Expand Down

0 comments on commit bcb7c2b

Please sign in to comment.