mariotoffia / FluentDocker

Use docker, docker-compose local and remote in tests and your .NET core/full framework apps via a FluentAPI
Apache License 2.0
1.31k stars 97 forks source link

Make it possible to remove docker images #265

Open cpwood opened 2 years ago

cpwood commented 2 years ago

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?

mariotoffia commented 2 years ago

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 :)

apazureck commented 2 years ago

Hey Mario,

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

cpwood commented 2 years ago

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();
mariotoffia commented 2 years ago

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 :)