Skip to content

Commit

Permalink
Fix: Tell the user when we can't remove the image if it's in use
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Webb <dan.webb@damacus.io>
  • Loading branch information
damacus committed Nov 15, 2023
1 parent 14c3e93 commit 018b983
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 @@ -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 018b983

Please sign in to comment.