简体   繁体   中英

Docker.Dotnet How to pull an Image

I want to pull and run an Image with Docker.DotNet and I am desperated, I have no Idea how to do this with this library.

Can anyone help me?

I looked at the tutorial on the https://github.com/microsoft/Docker.DotNet but that is not helpful.

 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);
        }

    }

I expect something to happen when I start task.wait()? But the it runs for several minutes and nothing happens.

Your code downloads the image and adds it to your local Docker registry. Run the command docker images from the command line and you should see that the image is there now.

Your image name looks wrong. You have the repository, but not the tag.

Looking at: https://hub.docker.com/_/microsoft-dotnet-core-sdk/

suggests you need: mcr.microsoft.com/dotnet/core/sdk:2.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM