Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 823
Christian Avatar asked Oct 15 '22 13:10

Christian


1 Answers

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.

like image 62
Hans Kilian Avatar answered Oct 19 '22 01:10

Hans Kilian