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 <[email protected]>
Co-authored-by: Edward Smith <[email protected]>
  • Loading branch information
damacus and ersmith committed Nov 27, 2023
1 parent 01acb1e commit 3c4da7d
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])

Check failure on line 53 in lib/kitchen/docker/helpers/image_helper.rb

View workflow job for this annotation

GitHub Actions / lint-unit / Chefstyle on Ruby 3.2

[Correctable] Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

def build_image(state, dockerfile)
Expand Down

0 comments on commit 3c4da7d

Please sign in to comment.