|
3 | 3 | using System;
|
4 | 4 | using System.Collections.Generic;
|
5 | 5 | using System.Diagnostics;
|
| 6 | +using System.IO; |
6 | 7 | using System.Linq;
|
7 | 8 | using System.Net.NetworkInformation;
|
8 | 9 | using System.Runtime.InteropServices;
|
@@ -55,8 +56,7 @@ public async Task StartContainer()
|
55 | 56 | hostCfg.PortBindings = new Dictionary<string, IList<PortBinding>>();
|
56 | 57 | hostCfg.PortBindings.Add($"{InternalPort}/tcp", new PortBinding[] { pb });
|
57 | 58 |
|
58 |
| - //await docker.Images.PullImageAsync(new ImagesPullParameters() { Parent = ImageName, Tag = ImageTag }, null); |
59 |
| - Process.Start("docker", $"pull {ImageName}:{ImageTag}").WaitForExit(); |
| 59 | + await PullImage(ImageName, ImageTag); |
60 | 60 |
|
61 | 61 | var container = await docker.Containers.CreateContainerAsync(new CreateContainerParameters()
|
62 | 62 | {
|
@@ -100,6 +100,25 @@ public async Task StartContainer()
|
100 | 100 | }
|
101 | 101 | }
|
102 | 102 |
|
| 103 | + public async Task PullImage(string name, string tag) |
| 104 | + { |
| 105 | + var images = docker.Images.ListImagesAsync(new ImagesListParameters()).Result; |
| 106 | + var exists = images |
| 107 | + .Where(x => x.RepoTags != null) |
| 108 | + .Any(x => x.RepoTags.Contains($"{name}:{tag}")); |
| 109 | + |
| 110 | + if (exists) |
| 111 | + return; |
| 112 | + |
| 113 | + var stream = await docker.Images.PullImageAsync(new ImagesPullParameters() { Parent = name, Tag = tag }, null); |
| 114 | + |
| 115 | + using (StreamReader reader = new StreamReader(stream)) |
| 116 | + { |
| 117 | + while (!reader.EndOfStream) |
| 118 | + Debug.WriteLine(reader.ReadLine()); |
| 119 | + } |
| 120 | + } |
| 121 | + |
103 | 122 | public void Dispose()
|
104 | 123 | {
|
105 | 124 | docker.Containers.KillContainerAsync(containerId, new ContainerKillParameters()).Wait();
|
|
0 commit comments