pkamala
pkamala

Reputation: 1

Rancher Desktop with WSL integration - HttpRequestException when trying to list images from local registry using Docker .Net client

Rancher Desktop with WSL integration - HttpRequestException when trying to list images from local registry using Docker .Net client

I'm new to working with containers and also .Net. I have a Visual Studio worker service project from which I wish to launch a container. The project has container support enabled with Linux as the container OS. I'm using Rancher Desktop with WSL integration enabled. I have a local Docker registry (localhost:5000) and I'm trying to start an image from it.

I have a DockerService class and in the constructor I do:

        _dockerClient = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();

I have a method CreateAndStartContainerAsync where I do:

            // Check if the image is available locally
            var images = await _dockerClient.Images.ListImagesAsync(new ImagesListParameters
            {
                Filters = new Dictionary<string, IDictionary<string, bool>>
                {
                    { "reference", new Dictionary<string, bool> { { imageName, true } } }
                }
            });

When I run the service from within Visual Studio debugger, the ListImagesAsync call is failing with below exception:

System.Net.Http.HttpRequestException: Connection failed System.Net.Sockets.SocketException (99): Cannot assign requested address at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ConnectAsync(Socket socket) at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP, CancellationToken cancellationToken) at System.Net.Sockets.Socket.ConnectAsync(EndPoint remoteEP) at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<<-ctor>b__1>d.MoveNext() at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<.ctor>b__1(String host, Int32 port, CancellationToken cancellationToken) at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at System.Net.Http.HttpClient.g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at System.Net.Http.HttpClient.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancellationToken) at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary2 headers, IRequestContent data, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary2 headers, IRequestContent data, CancellationToken cancellationToken) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, TimeSpan timeout, CancellationToken token) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, TimeSpan timeout, CancellationToken token) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, CancellationToken token) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, CancellationToken token) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, CancellationToken token) at Docker.DotNet.ImageOperations.ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at Docker.DotNet.ImageOperations.ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken) at GatewareBuilderBackend.DockerService.CreateAndStartContainerAsync(String imageName, String registryUrl, List1 envVars, List1 volumeBinds, List1 commands) in C:\Users\ips85131\source\repos\GatewareBuilder\GatewareBuilderBackend\DockerService.cs:line 27 at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at GatewareBuilderBackend.DockerService.CreateAndStartContainerAsync(String imageName, String registryUrl, List1 envVars, List1 volumeBinds, List1 commands) at GatewareBuilderBackend.Worker.RunDockerContainer(String tempFolderPath, CancellationToken stoppingToken) in C:\Users\ips85131\source\repos\GatewareBuilder\GatewareBuilderBackend\Worker.cs:line 194 at GatewareBuilderBackend.Worker.ProcessBuildRequest(BuildRequest buildRequest, CancellationToken stoppingToken) in C:\Users\ips85131\source\repos\GatewareBuilder\GatewareBuilderBackend\Worker.cs:line 99 at GatewareBuilderBackend.Worker.<>c__DisplayClass13_0.b__0(Object _, BasicDeliverEventArgs ea) in C:\Users\ips85131\source\repos\GatewareBuilder\GatewareBuilderBackend\Worker.cs:line 55 at RabbitMQ.Client.Events.EventingBasicConsumer.HandleBasicDeliver(String consumerTag, UInt64 deliveryTag, Boolean redelivered, String exchange, String routingKey, IBasicProperties properties, ReadOnlyMemory1 body) at RabbitMQ.Client.Impl.ConcurrentConsumerDispatcher.<>c__DisplayClass10_0.<HandleBasicDeliver>b__0() at RabbitMQ.Client.Impl.ConsumerWorkService.WorkPool.Loop() at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.ExecutionContextCallback(Object s) at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext(Thread threadPoolThread) at System.Runtime.CompilerServices.AsyncTaskMethodBuilder1.AsyncStateMachineBox1.MoveNext() at System.Threading.ThreadPoolWorkQueue.Dispatch() at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart() End of stack trace from previous location --- at Docker.DotNet.DockerClient.<>c__DisplayClass6_0.<<-ctor>b__1>d.MoveNext() End of stack trace from previous location --- at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) End of inner exception stack trace --- at Microsoft.Net.Http.Client.ManagedHandler.ProcessRequestAsync(HttpRequestMessage request, CancellationToken cancellationToken) at Microsoft.Net.Http.Client.ManagedHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.<SendAsync>g__Core|83_0(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationTokenSource cts, Boolean disposeCts, CancellationTokenSource pendingRequestsCts, CancellationToken originalCancellationToken) at Docker.DotNet.DockerClient.PrivateMakeRequestAsync(TimeSpan timeout, HttpCompletionOption completionOption, HttpMethod method, String path, IQueryString queryString, IDictionary2 headers, IRequestContent data, CancellationToken cancellationToken) at Docker.DotNet.DockerClient.MakeRequestAsync(IEnumerable1 errorHandlers, HttpMethod method, String path, IQueryString queryString, IRequestContent body, IDictionary2 headers, TimeSpan timeout, CancellationToken token) at Docker.DotNet.ImageOperations.ListImagesAsync(ImagesListParameters parameters, CancellationToken cancellationToken)

When I open a bash shell into the service container, I can see that /var/run/docker.sock does not exist in it. But this file is visible inside my WSL Ubuntu installation.

In Rancher Desktop's docker.log file I can see the following lines with the time stamp around the time I start the debugger.

time="2024-11-01T17:28:12.712611021Z" level=error msg="Error running exec d119f88118923d47718785b85ca3ac27ae67c32a10abf7e451af6d0b24c87f11 in container: exec attach failed: error attaching stdout stream: write unix /mnt/wsl/rancher-desktop/run/docker.sock->@: write: broken pipe" spanID=b231c9385f0e6d78 traceID=a2a4de3e880e7cd8ef85cd7d391f8333 Line 2974: time="2024-11-01T17:28:13.865186600Z" level=error msg="Error running exec b6239fde44df87f68dd881aeb89a8957ae270a13ed0282e7cd10a6ccccd16e7d in container: exec attach failed: error attaching stdout stream: write unix /mnt/wsl/rancher-desktop/run/docker.sock->@: write: broken pipe" spanID=0bd959472e9ef15f traceID=0a6fc51338798dfd94f42775bfa0cfe3

Is what I'm trying to do even possible? If so, what is the correct way to do this? An additional note is that I'm using the local registry for testing purposes and will be using a remote registry eventually.

Upvotes: 0

Views: 60

Answers (0)

Related Questions