-
-
Notifications
You must be signed in to change notification settings - Fork 475
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
How to remove images created with FromDockerfile? #303
Comments
This is a good question, the java library has an automatic detection feature: https://www.testcontainers.org/features/creating_images/ but Java has a trigger that can be used when a test suite ends, we do not have this luxury in Go. So we can label every image with a specific label that detects the image created by testcontainers in this way users can figure out a way to list and remove the images with a specific label. But this is not much different compared with |
This would make removing the images easier. In my case, this is only a problem when running the tests locally, not really a problem, but would be nice to have :). Thanks for the reply! |
Well it's not actually Java but the test runner you use. We use godog for cucumber scenarios and the test runner provides life cycle hooks for before/after test suite, before/after scenario and before/after step, and there I destroy whatever is needed. |
I was having this "problem" and it was kind of boring having to manually delete the containers. Up til now, my machine didn't explode so... 🤷
where |
I delete images by repo:tag something like this: func BuildFromDockerfile(ctx context.Context, req tc.ContainerRequest) (string, func(context.Context) error, error) {
prv, err := tc.NewDockerProvider()
if err != nil {
return "", nil, err
}
tag, err := prv.BuildImage(ctx, &req)
if err != nil {
return "", nil, err
}
cleanup := func(ctx context.Context) error {
cli, err := client.NewClientWithOpts(
client.FromEnv,
client.WithAPIVersionNegotiation(),
)
if err != nil {
return err
}
opts := types.ImageRemoveOptions{
Force: true,
PruneChildren: true,
}
_, err = cli.ImageRemove(ctx, tag, opts)
return err
}
return tag, cleanup, nil
} |
This custom One thing I noticed though is that intermediate containers and images still hang around, I proposed this change to remove them once the build is complete: #403 What do you think about making image removal getting triggered on |
I like this approach @gaborszakacs, and it's something I was discussing with @kiview the other day. If this is something you can provide in a PR, I would be more than grateful to review it. Thanks in advance! |
Thanks @mdelapenya, for the input, I gave it a shot: #405 |
@mdelapenya gentle ping, these two PRs addresses this issue, can you take a look at them pls? |
I think we can close this one, as above PRs have been merged. Thank you all for your feedback |
I've been creating some of my containers using
![image](https://user-images.githubusercontent.com/795838/112842248-bf4dff80-9077-11eb-8720-456925137672.png)
FromDockerfile
, is there any way to remove the built images after my tests run? The image list starts to get a bit crowded after a few test runs with all the tags testcontainers create.The text was updated successfully, but these errors were encountered: