2

How can I connect to my local Docker service using Docker.DotNet library in Linux environment (considering that I am using .Net Core 2.0)?

I think it is somehow related to /var/run/docker.sock file, but I could not figure out how to achieve that.

Mohammed Noureldin
  • 14,913
  • 17
  • 70
  • 99

2 Answers2

2

This issue has been reported, and according to the discussion in here, the following should work on linux:

DockerClient client = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock"))
     .CreateClient()
yamenk
  • 46,736
  • 10
  • 93
  • 87
0

I created a kind of helpers class which provide the default local api uri depending on the underlying OS:

public static class Docker
{
    static Docker()
    {
        DefaultLocalApiUri = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) 
            ? new Uri("npipe://./pipe/docker_engine")
            : new Uri("unix:/var/run/docker.sock");
    }

    public static Uri DefaultLocalApiUri { get; }
}
Natalie Perret
  • 8,013
  • 12
  • 66
  • 129