2

如何在Linux环境中使用Docker.DotNet库连接到我的本地 Docker 服务(考虑到我使用的是 .Net Core 2.0)?

我认为它与/var/run/docker.sock文件有关,但我不知道如何实现。

4

2 回答 2

2

已报告此问题,根据此处的讨论,以下内容应适用于 linux:

DockerClient client = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock"))
     .CreateClient()
于 2018-01-02T08:32:18.653 回答
0

我创建了一种帮助类,它根据底层操作系统提供默认的本地 api uri:

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; }
}
于 2019-05-22T19:50:34.793 回答