Open JonathanBout opened 6 months ago
I am curious and interested in which language feature (syntax sugar) I missed. I am unable to compile your provided example. Can you share the docs for the language feature that introduces the syntax you are using (initializing the dictionary)? My test runs fine:
var containersListParameters = new ContainersListParameters();
containersListParameters.Filters = new Dictionary<string, IDictionary<string, bool>> { { "status", new Dictionary<string, bool> { { "exited", true } } } };
The filter only returns exited containers.
Oh my example indeed doesn't compile 😅 I'll update it.
But it does correctly return all exited containers, yes. But it also returns exited containers when I use { "exited", false }
AFAIK the bool flag does nothing. I have 4 container (3 exited, 1 running). I get the following results, which look Ok:
Returns 4:
var containersListParameters = new ContainersListParameters();
// containersListParameters.Filters = new Dictionary<string, IDictionary<string, bool>> { { "status", new Dictionary<string, bool> { { "exited", true } } } };
containersListParameters.All = true;
Returns 1:
var containersListParameters = new ContainersListParameters();
// containersListParameters.Filters = new Dictionary<string, IDictionary<string, bool>> { { "status", new Dictionary<string, bool> { { "exited", true } } } };
containersListParameters.All = false;
Returns 3:
var containersListParameters = new ContainersListParameters();
containersListParameters.Filters = new Dictionary<string, IDictionary<string, bool>> { { "status", new Dictionary<string, bool> { { "exited", true } } } };
// containersListParameters.All = false;
But why was it added then? It's a bit confusing your 3rd example returns the same as this:
var containersListParameters = new ContainersListParameters();
containersListParameters.Filters = new Dictionary<string, IDictionary<string, bool>> { { "status", new Dictionary<string, bool> { { "exited", false} } } };
your 3rd example returns the same as this
I know, but I do not know why there is the additional bool
value, if you look into the Docker Engine API, it says:
Filters to process on the container list, encoded as JSON (a map[string][]string). For example, {"status": ["paused"]} will only return paused containers.
Maybe it was necessary in a previous API version? If you want to know the exact details, you probably need to look at QueryStringtrue
or false
is used. And according to the API docs, I do not expect them to be necessary at all. Sorry, I cannot help more.
Does any main developer of this project know what the bool
flag is supposed to do in a filter?
It definitely does something with the formatting, see this example:
var images1 = await client.Images.ListImagesAsync(
new ImagesListParameters()
{
Filters = new Dictionary<string, IDictionary<string, bool>>()
{
{"dangling", new Dictionary<string, bool>() {{"true", true}}}
}
});
// Success
Changing the bool
flag to false {"dangling", new Dictionary<string, bool>() {{"true", FALSE}}}
resulted in:
Unhandled exception. Docker.DotNet.DockerApiException: Docker API responded with status code=BadRequest, response={"message":"invalid filter 'dangling=[true]'"}
at Docker.DotNet.DockerClient.HandleIfErrorResponseAsync(HttpStatusCode statusCode, HttpResponseMessage response, IEnumerable
1 handlers) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable
1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary`2 headers, TimeSpan timeout, CancellationToken token) at Docker.DotNet.ImageOperations.ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken)
The brackets dangling=[true]
are added in case the bool
is set to false
. In case true
it is dangling=true
.
Output of
dotnet --info
:Output
What version of Docker.DotNet?:
Steps to reproduce the issue:
false
:What actually happened?: I got a list of all exited containers
What did you expect to happen?: I get a list of all not exited containers
Additional information: I use ASP.NET Core with dependency injection. The Docker client is registered as a singleton: