Christian
Christian

Reputation: 1194

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.

Upvotes: 5

Views: 4182

Answers (2)

Hans Kilian
Hans Kilian

Reputation: 25070

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.

Upvotes: 3

Owen Pauling
Owen Pauling

Reputation: 11841

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

Upvotes: 1

Related Questions