Docker.Dotnet 如何拉取镜像?

5

我希望使用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()时,我期望会发生某些事情。但是它运行了几分钟,却没有任何反应。


如果 https://github.com/dotnet/Docker.DotNet#example-create-an-image-by-pulling-from-docker-registry 的文档能像这篇文章一样好就好了... - Ryan Williams
2个回答

3

你的代码下载了这个镜像并将其添加到你本地的Docker注册表中。从命令行运行docker images命令,你应该能够看到该镜像已经存在。

注:Original Answer翻译成"最初的回答"为不恰当的翻译,请提供正确的上下文信息。

是的,你说得对。昨天我重新安装了Docker,之后它就可以工作了,但我不知道为什么。 - Christian

1

但这并没有改变任何事情。我添加了最新的内容,但任务仍在运行,什么也没有发生。 - Christian
@ChristianSchulze 你检查过是否可以从命令行中拉取这个 Docker 镜像了吗? - Owen Pauling

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接