gpt4 book ai didi

c# - Docker.Dotnet 如何拉取镜像

转载 作者:太空宇宙 更新时间:2023-11-03 12:01:09 28 4
gpt4 key购买 nike

我想使用 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() 时会发生什么?但是它运行了几分钟却什么也没有发生。

最佳答案

您的代码下载图像并将其添加到本地 Docker 注册表。从命令行运行命令 docker images,您应该会看到图像现在就在那里。

关于c# - Docker.Dotnet 如何拉取镜像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56931378/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com