我希望使用Docker.DotNet拉取和运行镜像,但我感到绝望,不知道如何使用这个库完成此操作。
有人能帮帮我吗?
我看了https://github.com/microsoft/Docker.DotNet上的教程,但并没有什么帮助。
public class DockerService
{
private readonly DockerClient DockerClient;
public DockerService()
{
if (OperatingSystem.IsWindows())
{
DockerClient = new DockerClientConfiguration(new Uri("npipe://./pipe/docker_engine")).CreateClient();
}
else if (OperatingSystem.IsLinux())
{
DockerClient = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient();
}
else
{
throw new Exception("unknown operation system");
}
}
public void StartCompose()
{
var progress = new Progress<JSONMessage>();
var task = PullImage(
new ImagesCreateParameters()
{
FromImage = "mcr.microsoft.com/dotnet/core/sdk",
Tag = "latest"
},null,
progress);
task.Wait();
}
private Task PullImage(ImagesCreateParameters imagesCreateParameters, AuthConfig authConfig,
Progress<JSONMessage> progress)
{
return DockerClient.Images.CreateImageAsync(imagesCreateParameters, authConfig, progress);
}
}
当我执行task.wait()时,我期望会发生某些事情。但是它运行了几分钟,却没有任何反应。