如何在Linux环境中使用Docker.DotNet库连接到我的本地 Docker 服务(考虑到我使用的是 .Net Core 2.0)?
我认为它与/var/run/docker.sock
文件有关,但我不知道如何实现。
如何在Linux环境中使用Docker.DotNet库连接到我的本地 Docker 服务(考虑到我使用的是 .Net Core 2.0)?
我认为它与/var/run/docker.sock
文件有关,但我不知道如何实现。
已报告此问题,根据此处的讨论,以下内容应适用于 linux:
DockerClient client = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock"))
.CreateClient()
我创建了一种帮助类,它根据底层操作系统提供默认的本地 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; }
}