我想用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);
}
}
我希望当我开始任务时会发生什么。但是它运行了几分钟,什么也没发生。
您的代码下载图像并将其添加到您的本地Docker注册表中。从命令行中运行命令docker images
,您应该看到图像现已存在。
您的图像名称看起来错误。您有存储库,但没有标签。
查看:https://hub.docker.com/_/microsoft-dotnet-core-sdk/
建议您需要:mcr.microsoft.com/dotnet/core/sdk:2.2