Skip to content
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

recieving single container from ContainerListResponse #641

Open
hakimdotdev opened this issue Jun 6, 2023 · 2 comments
Open

recieving single container from ContainerListResponse #641

hakimdotdev opened this issue Jun 6, 2023 · 2 comments

Comments

@hakimdotdev
Copy link

hakimdotdev commented Jun 6, 2023

Output of dotnet --info:

.NET SDK:
Version: 7.0.302
Commit: 990cf98a27
What version of Docker.DotNet?:

Latest Nuget
Steps to reproduce the issue:

 private async Task<ContainerListResponse> GetContainerFromName(string containerName)
    {
        var containers = await new DockerClientConfiguration().CreateClient().Containers.ListContainersAsync(
            new ContainersListParameters { All = true }
        );
        var container = containers.FirstOrDefault(c => c.Names.Contains(containerName));

        return container;
    }

public async Task<IActionResult> StartContainer(string container)
    {
        var containerObj = await GetContainerFromName(container);
        var i = await new DockerClientConfiguration().CreateClient().Containers.InspectContainerAsync(containerObj.ID);

Or Any other Linq Query
What actually happened?:*
Sequence is Empty

What did you expect to happen?:
To be able to retrieve the First or really any container from the IList with query or somehow to be able to get .ID for StartAsync

var start = await new DockerClientConfiguration().CreateClient().Containers.StartContainerAsync(containerObj.ID, new ContainerStartParameters());

I'm trying to get a single container followed by its ID from name.Is there some way to easily achieve this, which I'm missing out on? I couldn't deduce anything off of the documentation available in the repo. Thanks in Advance.

@HofmeisterAn
Copy link
Contributor

I am unable to recreate the issue. I am receiving the created containers. Is the variable containers empty, or does it simply not contain the container with the expected name?
Screenshot 2023-06-07 at 10 32 54

@hakimdotdev
Copy link
Author

hakimdotdev commented Jun 7, 2023


            var containers = await new DockerClientConfiguration().CreateClient().Containers.ListContainersAsync(new ContainersListParameters());
            _containers.AddRange(containers);

        var statuses = _containers.Select(c => $"{c.Names.FirstOrDefault()}: {c.State}");
        
        return statuses.ToList();

will return all containers with name and state properly but trying to get the object or just the id from the name will leave the passed object empty.

EDIT:

The name is passed properly, what had to be done is querying Names[0] not the IList itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants