Chr*_*ian 5 c# docker .net-core
我想使用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);
}
}
Run Code Online (Sandbox Code Playgroud)
我期望启动 task.wait() 时会发生一些事情?但它运行了几分钟却没有任何反应。
| 归档时间: |
|
| 查看次数: |
3474 次 |
| 最近记录: |