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