Skip to content

Fix unsafe container cleanup in delete_image#56

Merged
chorrell merged 1 commit intomainfrom
fix/safe-container-cleanup
Feb 10, 2026
Merged

Fix unsafe container cleanup in delete_image#56
chorrell merged 1 commit intomainfrom
fix/safe-container-cleanup

Conversation

@chorrell
Copy link
Copy Markdown
Owner

Problem

The delete_image helper method was stopping ALL Docker containers on the system before removing test images. This is dangerous because it could interrupt unrelated containers that developers have running.

Solution

Updated the cleanup logic to only stop and remove containers that were specifically created from the test image being cleaned up. This is done by:

  1. Iterating through all containers
  2. Checking if each container's image ID matches the test image ID
  3. Only stopping/removing containers that match

Impact

This makes the test suite safer to run on development machines where other Docker containers may be running.

Previously, delete_image stopped ALL containers on the system before
removing test images, which could disrupt unrelated containers.

Changes:
- Only stop and remove containers created from the specific test image
- Match containers using substring comparison to handle sha256: prefix
- Check container state before stopping to avoid unnecessary operations
- Handle NotModifiedError for already-stopped containers

This makes the test suite safe to run on development machines where
other Docker containers may be running.

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
@chorrell chorrell force-pushed the fix/safe-container-cleanup branch from 550b002 to 6ff56c8 Compare February 10, 2026 21:34
@chorrell chorrell merged commit fcdf6bd into main Feb 10, 2026
1 check passed
@chorrell chorrell deleted the fix/safe-container-cleanup branch February 10, 2026 21:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant