Skip to content

InspectContainerAsync throws a 'Connection failed' error. #697

@msdYqb

Description

@msdYqb

I'm on Windows, and I want to retrieve the exposed ports of the currently running ASP.NET Core MVC Linux image. The InspectContainerAsync method throws a System.Net.Http.HttpRequestException: 'Connection failed' error
SocketException: Cannot assign requested address

public static async Task<List<int>> GetExposedPorts()
{
    var portsList = new List<int>();
    var dockerClient = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();
    var dockerId = GetDockerId();
    var containerInspect = await dockerClient.Containers.InspectContainerAsync(dockerId);

    foreach (var port in containerInspect.NetworkSettings.Ports)
        portsList.Add(int.Parse(port.Key));

    return portsList;
}

The GetDockerId method returns the correct Docker ID, but I still can't inspect the container.

Here are the steps to reproduce: In Visual Studio 2022, create a new MVC project. Enable container support. Set the container OS to Linux. Set the container build type to Dockerfile. In the Debug menu, select 'Run in Container (Dockerfile).' Run the code provided above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions