dotnet / dotnet/Docker.DotNet

InspectContainerAsync throws a 'Connection failed' error.

Open
#697 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

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> GetExposedPorts()
{
var portsList = new List();
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.

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.