Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix] Coordinate image removals after stopping containers #1745

Merged
merged 1 commit into from Aug 25, 2019

Conversation

aguibert
Copy link
Contributor

I have been using ImageFromDockerFile to build images on the fly for my tests, which are supposed to be cleaned up by default.

However, I noticed that the images were being untagged and left as dangling images in most cases (see MicroShed/microshed-testing#9)

Currently Testcontianers registers shutdown hooks for:

  • stopping and removing containers
  • removing images

However, it does not coordinate these shutdown hooks. Typically the remove image hook fires before the stop+remove container hook completes, which leaves the dangling images. To solve this, we can merge the two shutdown hooks into one and therefore guarantee containers are stopped+removed before we attempt to do the image removal.

@aguibert aguibert changed the title Coordinate image removals after stopping containers [Bug] Coordinate image removals after stopping containers Aug 15, 2019
@aguibert aguibert changed the title [Bug] Coordinate image removals after stopping containers [Bugfix] Coordinate image removals after stopping containers Aug 15, 2019
@rnorth
Copy link
Member

rnorth commented Aug 21, 2019

Aha, thanks @aguibert. This looks very sensible. We probably should have consolidated much sooner.

I'll have a review and think about this, but on the face of it this seems fine.
Cheers

@bsideup bsideup added this to the next milestone Aug 25, 2019
Copy link
Member

@bsideup bsideup left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, but will let @rnorth to review it as well (since he indicated an interest in it and may know some tricky details about it)

@bsideup bsideup mentioned this pull request Aug 25, 2019
2 tasks
Copy link
Member

@rnorth rnorth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to confirm, I'm happy with this 😄
Thanks once again @aguibert!

@rnorth rnorth merged commit aab9aa0 into testcontainers:master Aug 25, 2019
@minakh1993
Copy link

minakh1993 commented Apr 30, 2023

I have the same problem in version 1.17.5. defined image as below but after test execution created image is not removed.
new CmApplicationContainer(new ImageFromDockerfile().withDockerfile(Path.of(dockerfile)))
I checked the changed code in this commit. but changes doesn't seem to exist in 1.17.5 version(checked compiled class of ImageFromDockerfile resolve method). thanks in advance for your help.
update : an extra image is created out of nowhere that has no tag or name:
REPOSITORY TAG IMAGE ID CREATED SIZE
none none 888ca210c487 3 minutes ago 605MB

the main image that is created from imageFromDockerfile is removed correctly but this unknown image still exist after tests.
as i inspect the problem deeply this problem happen for multi-stage dockerfiles.

#6948

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants