dotnet / dotnet/Docker.DotNet

ListContainersAsync returns all containers

Open
#426 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
2.4k
Forks
416
PR merge metrics
No merged PRs in 30d

Description

**Output of `dotnet --info`:**

```
.NET Core SDK (reflecting any global.json):
Version: 3.0.100
Commit: 04339c3a26

Runtime Environment:
OS Name: Windows
OS Version: 10.0.18362
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\3.0.100\

Host (useful for support):
Version: 3.0.0
Commit: 7d57652f33

.NET Core SDKs installed:
2.1.802 [C:\Program Files\dotnet\sdk]
3.0.100 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
```

**What version of Docker.DotNet?:**

```
v3.125.2
```

**Issue:**

In order to list current running containers, a lot of people do something along the lines of the following:
```cs
var dockerClient = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
var currentContainers = await dockerClient.Containers.ListContainersAsync(
new ContainersListParameters(){
Filters = new Dictionary>
{
{
"status", new Dictionary
{
{"running", true}
}
}
});
```

But this is entirely unnecessary and by default, using the `All = false` parameter should return only current running containers, but instead it returns all containers.
We can see the appropriate behavior of the Docker API by querying `localhost:2375/containers/json` which shows only the current running containers, but for explicitness, `localhost:2375/containers/json?all=false` returns only current running containers as well.
See [Docker Engine API v1.25](https://docs.docker.com/engine/api/v1.25/#operation/ContainerLists)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.