dotnet / Docker.DotNet

:whale: .NET (C#) Client Library for Docker API
https://www.nuget.org/packages/Docker.DotNet/
MIT License
2.26k stars 380 forks source link

System.Net.Sockets.SocketException: Trying to connect to docker instance running under WSL #561

Open TomBruns opened 2 years ago

TomBruns commented 2 years ago

Summary Docker installed and running under WSL/Ubuntu (not Windows Docker Desktop) C#/.NET 6 program using Docker.DotNet executed in a Ubuntu session cannot connect (timeout) to Docker instance

Output of dotnet --info:

.NET SDK (reflecting any global.json):
 Version:   6.0.202
 Commit:    f8a55617d2

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

Host (useful for support):
  Version: 6.0.4
  Commit:  be98e88c76

.NET SDKs installed:
  5.0.405 [C:\Program Files\dotnet\sdk]
  6.0.202 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.24 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.14 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
  https://aka.ms/dotnet-download

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Docker Buildx (Docker Inc., v0.8.1-docker)
  compose: Docker Compose (Docker Inc., v2.2.3)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 16
  Running: 13
  Paused: 0
  Stopped: 3
 Images: 1072
 Server Version: 20.10.14
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3df54a852345ae127d1fa3092b95168e4a88e2f8
 runc version: v1.0.3-0-gf46b6ba
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
 Kernel Version: 5.10.16.3-microsoft-standard-WSL2
 Operating System: Ubuntu 20.04.4 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 24.84GiB
 Name: DS-AMER-ohqtego
 ID: FXNE:2FQB:JKG3:LWVC:RCTK:FGNX:CY3S:2NMW:2WSK:K7MW:223G:U7GF
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support

What version of Docker.DotNet?:

    <PackageReference Include="Docker.DotNet" Version="3.125.5" />

Steps to reproduce the issue:

  1. Run this code in a .NET 6 console app (in an wsl/ubuntu session)

    Note: both new DockerClientConfiguration generate the same error

    
    //DockerClient client = new DockerClientConfiguration().CreateClient();
    DockerClient client = new DockerClientConfiguration(new Uri(@"unix:///var/run/docker.sock"),
    null, 
    new TimeSpan(0, 0, 1000))
    .CreateClient(new System.Version(@"1.41"));
        IList<ContainerListResponse> containers = await client.Containers.ListContainersAsync(
                                                                new ContainersListParameters() 
                                                                { 
                                                                    Limit = 10, 
                                                                });

What actually happened?:

Exception is thrown on ListContainersAsync

Unhandled exception. System.Net.Http.HttpRequestException: Connection failed
 ---> System.Net.Sockets.SocketException (10050): A socket operation encountered a dead network.
   at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.CreateException(SocketError error, Boolean forAsyncThrow)

What did you expect to happen?:

API call returns a list of containers

Additional information:

Verified socket exists

tomb@DS-AMER-ohqtego:/mnt/c/Users/e5593810$ ls -al /var/run/docker.sock
srw-rw---- 1 root docker 0 May 12 08:37 /var/run/docker.sock

Docker instance is accessible via Portainer image

Normal docker command line operations works

tomb@DS-AMER-ohqtego:/mnt/c/Users/e5593810$ docker image ls fis.*:latest
REPOSITORY                                      TAG       IMAGE ID       CREATED        SIZE
********   latest    465806e3ec7d   25 hours ago   207MB
********   latest    dcf0da88d363   26 hours ago   218MB
********   latest    1031696887f7   27 hours ago   226MB
********   latest    3b1b93137c0c   27 hours ago   218MB
********   latest    b68d227de62b   27 hours ago   319MB
********   latest    5e892ae32eed   27 hours ago   264MB
********   latest    07521ab81d9a   27 hours ago   1.45GB
********   latest    0ccf149128ec   40 hours ago   218MB
dgvives commented 2 years ago

Was this working before? I updated docker yesterday and a previously existing app using Docker.DotNet library stopped working.

Had to uninstall it and got a release from I think January

Tried docker on Windows and WSL, the docker API was not responding