Skip to content

Commit bcb7c2b

Browse files
damacusersmith
andauthored
feat: Tell the user when we can't remove the image if it's in use (#406)
Signed-off-by: Dan Webb <dan.webb@damacus.io> Co-authored-by: Edward Smith <edward@ersmith.me>
1 parent 90bf689 commit bcb7c2b

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

lib/kitchen/docker/helpers/image_helper.rb

+10-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,16 @@ def parse_image_id(output)
4141

4242
def remove_image(state)
4343
image_id = state[:image_id]
44-
docker_command("rmi #{image_id}")
44+
if image_in_use?(state)
45+
info("[Docker] Image ID #{image_id} is in use. Skipping removal")
46+
else
47+
info("[Docker] Removing image with Image ID #{image_id}.")
48+
docker_command("rmi #{image_id}")
49+
end
50+
end
51+
52+
def image_in_use?(state)
53+
docker_command("ps -a", suppress_output: !logger.debug?).include?(state[:image_id])
4554
end
4655

4756
def build_image(state, dockerfile)

0 commit comments

Comments
 (0)