FluentDocker icon indicating copy to clipboard operation
FluentDocker copied to clipboard

Make it possible to remove docker images

Open cpwood opened this issue 2 years ago • 4 comments

I'm using this excellent package in xUnit integration tests that run as part of a GitHub Action.

The code I'm testing interacts with various databases, e.g. SQL Server, MySQL, Postgres, CosmosDB, etc. It's basically a data manipulation library and the list of data sources to test against is quite long.

My concern is that we only receive around 20GB of disk storage on the build agent which will quickly get used up by pulled images.

The strategy I'm hoping to use to handle this is to run integration tests serially so I'm only running one Docker image at a time and then to remove an image when the container is stopped / disposed.

I can't seem to find any way of removing images from the host. Is this definitely the case or am I just not looking hard enough?

cpwood avatar Jun 29 '22 03:06 cpwood

Hi @cpwood - I'm glad you like it! :) You are correct, there's no way of doing docker rmi with the library. If you run them as docker compose you can use ImageRemovalOption.All or ImageRemovalOption.Local when doing Compose.ComposeDown.

However, it should be an option to remove the image in the client, service and in the fluent API!

Cheers, Mario :)

mariotoffia avatar Jun 29 '22 11:06 mariotoffia

Hey Mario,

As I need this feature, too, how would you implement this? Can I send commands directly to docker using FluentDocker?

apazureck avatar Jul 21 '22 19:07 apazureck

Here's how I ended up doing it; not sure if there's a better way..

                    // Remove the image from the host to conserve disk space.
                    new ProcessExecutor<StringListResponseParser, IList<string>>(
                            "docker".ResolveBinary(),
                            $"rmi {image}").Execute();

cpwood avatar Jul 21 '22 20:07 cpwood

I'm on it - I've implemented half - doing response parsing so one can examine tags or image sha being removed (or not).

Cheers, Mario :)

mariotoffia avatar Jul 22 '22 08:07 mariotoffia