コード例 #1
0
        public async Task TryStart(CancellationToken cancellationToken = default)
        {
            var images = await _dockerClient.Images.ListImagesAsync(new ImagesListParameters
            {
                MatchName = ImageWithTag
            }, cancellationToken).NotOnCapturedContext();

            if (images.Count == 0)
            {
                // No image found. Pulling latest ..
                var imagesCreateParameters = new ImagesCreateParameters
                {
                    FromImage = _image,
                    Tag       = _tag,
                };

                await _dockerClient
                .Images
                .CreateImageAsync(imagesCreateParameters, null, IgnoreProgress.Forever, cancellationToken)
                .NotOnCapturedContext();
            }

            var containerId = await FindContainer(cancellationToken).NotOnCapturedContext()
                              ?? await CreateContainer(cancellationToken).NotOnCapturedContext();

            await StartContainer(containerId, cancellationToken);
        }
コード例 #2
0
        public Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IDictionary <string, string> headers, IProgress <JSONMessage> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            HttpMethod           httpMethod = HttpMethod.Post;
            BinaryRequestContent content    = null;

            if (imageStream != null)
            {
                content            = new BinaryRequestContent(imageStream, TarContentType);
                parameters.FromSrc = ImportFromBodySource;
            }

            IQueryString queryParameters = new QueryString <ImagesCreateParameters>(parameters);

            Dictionary <string, string> customHeaders = RegistryAuthHeaders(authConfig);

            if (headers != null)
            {
                foreach (string key in headers.Keys)
                {
                    customHeaders[key] = headers[key];
                }
            }

            return(StreamUtil.MonitorResponseForMessagesAsync(
                       this._client.MakeRequestForRawResponseAsync(httpMethod,
                                                                   "images/create", queryParameters, content, customHeaders, cancellationToken),
                       this._client,
                       cancellationToken,
                       progress));
        }
コード例 #3
0
        private async Task <bool> DownloadImageAsync(DockerImageId imageId, DockerClient dockerClient)
        {
            using var loggerScope = _logger.BeginScope($"Download docker image {imageId.FullName}");

            try
            {
                if (await CheckImageExistsAsync(imageId, dockerClient))
                {
                    return(true);
                }

                var parameters = new ImagesCreateParameters
                {
                    FromImage = imageId.Name,
                    Tag       = imageId.Tag
                };

                await dockerClient.Images.CreateImageAsync(parameters, null, new Progress <JSONMessage>());

                _logger.LogInformation("Image downloaded");

                return(true);
            }
            catch (Exception exception)
            {
                _logger.LogError(exception, "Failed to download image");

                return(false);
            }
        }
コード例 #4
0
        private async Task PullImage(CancellationToken ct)
        {
            if (ct.IsCancellationRequested)
            {
                return;
            }

            // todo: write a test for this
            var images = await DockerClient.Images.ListImagesAsync(new ImagesListParameters(), ct);

            if (images.Any(image => image.RepoTags != null && image.RepoTags.Contains(DockerImageName)))
            {
                _logger.LogDebug("Image already exists, not pulling: {}", DockerImageName);
                return;
            }

            _logger.LogInformation("Pulling container image: {}", DockerImageName);
            var createParameters = new ImagesCreateParameters
            {
                FromImage = DockerImageName,
                Tag       = DockerImageName.Split(':').Last(),
            };

            await DockerClient.Images.CreateImageAsync(
                createParameters,
                new AuthConfig(),
                new Progress <JSONMessage>(),
                ct);
        }
コード例 #5
0
        public Task CreateImageAsync(ImagesCreateParameters parameters, Stream imageStream, AuthConfig authConfig, IProgress <JSONMessage> progress, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            HttpMethod           httpMethod = HttpMethod.Get;
            BinaryRequestContent content    = null;

            if (imageStream != null)
            {
                content            = new BinaryRequestContent(imageStream, TarContentType);
                httpMethod         = HttpMethod.Post;
                parameters.FromSrc = ImportFromBodySource;
            }

            IQueryString queryParameters = new QueryString <ImagesCreateParameters>(parameters);

            return(StreamUtil.MonitorStreamForMessagesAsync(
                       this._client.MakeRequestForStreamAsync(this._client.NoErrorHandlers, httpMethod, "images/create", queryParameters, content, RegistryAuthHeaders(authConfig), cancellationToken),
                       this._client,
                       cancellationToken,
                       progress));
        }
コード例 #6
0
ファイル: DockerWrapper.cs プロジェクト: emallard/ci
        public async Task CreateImageIfNotFound(string repoTag)
        {
            var foundImage = await this.FindImage(repoTag);

            if (foundImage != null)
            {
                return;
            }

            using (var client = GetClient())
            {
                var parameters = new ImagesCreateParameters();
                var split      = repoTag.Split(':');
                parameters.FromImage = split[0];
                parameters.Repo      = split[0];
                parameters.Tag       = split[1];

                var progress = new DockerProgress(m => {
                    if (m.Progress != null)
                    {
                        Console.WriteLine(m.ID + " " + m.ProgressMessage /*+ " : " + m.Progress.Current + "/" + m.Progress.Total*/);
                    }
                });
                await client.Images.CreateImageAsync(parameters, null, progress);
            }
        }
コード例 #7
0
        private async Task <string> Create()
        {
            var progress = new Progress <JSONMessage>(async(m) =>
            {
                Console.WriteLine(m.Status);
                if (m.Error != null)
                {
                    await Console.Error.WriteLineAsync(m.ErrorMessage);
                }
            });

            var imagesCreateParameters = new ImagesCreateParameters
            {
                FromImage = Configuration.ImageName,
                Tag       = Configuration.Tag,
            };

            await _dockerClient.Images.CreateImageAsync(
                imagesCreateParameters,
                new AuthConfig(),
                progress,
                CancellationToken.None);

            var createContainersParams = ApplyConfiguration();
            var containerCreated       = await _dockerClient.Containers.CreateContainerAsync(createContainersParams);

            return(containerCreated.ID);
        }
コード例 #8
0
        private async Task StartContainer(string containerName)
        {
            this.Port = GetFreeTcpPort();
            string image      = "redditopenttd/openttd";
            string tag        = "1.11.2";
            string configPath = Path.Combine(Directory.GetCurrentDirectory(), nameof(Dockerized), "openttd.cfg");

            var pullParam = new ImagesCreateParameters()
            {
                FromImage = image,
                Tag       = tag
            };

            await client.Images.CreateImageAsync(pullParam, new AuthConfig(), new DockerizePullProgress(image));

            var response = await client.Containers.CreateContainerAsync(new Docker.DotNet.Models.CreateContainerParameters()
            {
                Name       = containerName,
                Image      = $"{image}:{tag}",
                HostConfig = new HostConfig
                {
                    PortBindings = new Dictionary <string, IList <PortBinding> >
                    {
                        {
                            "3982/tcp",
                            new List <PortBinding>
                            {
                                new PortBinding
                                {
                                    HostPort = Port.ToString()
                                }
                            }
                        }
                    },
                    Binds = new List <string>
                    {
                        $"{configPath}:/config/openttd.cfg:ro"
                    },
                },

                ExposedPorts = new Dictionary <string, EmptyStruct>
                {
                    {
                        "3982/tcp", new EmptyStruct()
                        {
                        }
                    }
                }
            });;

            await client.Networks.ConnectNetworkAsync("bridge", new NetworkConnectParameters
            {
                Container = response.ID,
            });

            await client.Containers.StartContainerAsync(response.ID, new ContainerStartParameters()
            {
            });
        }
コード例 #9
0
 /// <inheritdoc />
 public void PullImage(ImagesCreateParameters imagesCreateParameters, AuthConfig authConfig, Progress <JSONMessage> progress)
 {
     // Connect to local docker daemon
     using (DockerClient client = new DockerClientConfiguration(new Uri("unix:///var/run/docker.sock")).CreateClient())
     {
         client.Images.CreateImageAsync(imagesCreateParameters, authConfig, progress).Wait();
     }
 }
コード例 #10
0
 /// <summary>
 /// 拉取镜像
 /// </summary>
 /// <param name="revMsg"></param>
 /// <returns></returns>
 public async Task CreateImageAsync(ReceviceMessage revMsg)
 {
     string data = Encoding.UTF8.GetString(revMsg.payload);
     ImagesCreateParameters parameters = JsonConvert.DeserializeObject <ImagesCreateParameters>(data);
     AuthConfig             authConfig = JsonConvert.DeserializeObject <AuthConfig>(data);
     Progress <JSONMessage> progress   = new Progress <JSONMessage>();
     await _client.Images.CreateImageAsync(parameters, authConfig, progress);
 }
コード例 #11
0
 private async Task PullImage()
 {
     var imageCreateParams = new ImagesCreateParameters
     {
         FromImage = dynamodbLocalImage,
         Tag       = "latest"
     };
     await _dockerClient.Images.CreateImageAsync(imageCreateParams, null, new Progress <JSONMessage>());
 }
コード例 #12
0
        public void PullImage(string owner, string name, string tag, CancellationToken ct)
        {
            var pullParams = new ImagesCreateParameters
            {
                FromImage = string.IsNullOrEmpty(owner) ? name : $"{owner}/{name}",
                Tag       = tag
            };

            _client.Images.CreateImageAsync(pullParams, null, new Progress <JSONMessage>(msg => { }), ct).Wait(ct);
        }
コード例 #13
0
ファイル: DockerProxy.cs プロジェクト: wbskyboy/EasyNetQ
 public async Task PullImageAsync(string image, string tag, CancellationToken token = default)
 {
     var createParameters = new ImagesCreateParameters
     {
         FromImage = image,
         Tag       = tag
     };
     var progress = new Progress <JSONMessage>(jsonMessage => { });
     await client.Images.CreateImageAsync(createParameters, null, progress, token).ConfigureAwait(false);
 }
コード例 #14
0
ファイル: Docker.cs プロジェクト: lie112/ApsimX
 /// <summary>
 /// Pull an image from dockerhub.
 /// </summary>
 /// <param name="image">Name of the image (owner/organisation).</param>
 /// <param name="tag">Tag to be pulled.</param>
 /// <param name="cancelToken">Cancellation token.</param>
 public async Task PullImageAsync(string image, string tag, CancellationToken cancelToken)
 {
     ImagesCreateParameters imageParams = new ImagesCreateParameters()
     {
         FromImage = image,
         Tag       = tag,
     };
     AuthConfig auth = new AuthConfig();
     IProgress <JSONMessage> progress = new Progress <JSONMessage>(m => Console.WriteLine(m.Status));
     await client.Images.CreateImageAsync(imageParams, auth, progress, cancelToken);
 }
コード例 #15
0
        public Task <Stream> CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            return(PullImageAsync(new ImagesPullParameters()
            {
                All = false, Parent = parameters.Parent, RegistryAuth = parameters.RegistryAuth
            }, authConfig));
        }
コード例 #16
0
        public Task CreateImageAsync(ImagesCreateParameters parameters, AuthConfig authConfig, IProgress <JSONMessage> progress)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            return(PullImageAsync(new ImagesPullParameters()
            {
                All = false, Parent = parameters.Parent, RegistryAuth = parameters.RegistryAuth
            }, authConfig, progress));
        }
コード例 #17
0
        public Task <Stream> CreateImageAsync(ImagesCreateParameters parameters, AuthConfigParameters authConfig)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }

            string path = "images/create";
            Dictionary <string, string> headers = authConfig == null ? null : RegistryAuthHeaders(authConfig);
            IQueryString queryParameters        = new QueryString <ImagesCreateParameters>(parameters);

            return(this.Client.MakeRequestForStreamAsync(this.Client.NoErrorHandlers, HttpMethod.Post, path, queryParameters, headers, null, CancellationToken.None));
        }
コード例 #18
0
        /// <summary>
        /// Pulls specified image and ensures it is downloaded completely
        /// </summary>
        /// <param name="client">Docker client</param>
        /// <param name="image">Image name</param>
        /// <param name="token">Cancellation token</param>
        /// <returns>Task</returns>
        public static async Task PullImageAsync(this IDockerClient client, string image, CancellationToken token)
        {
            string[] imageParts     = image.Split(':');
            string   fromImage      = imageParts[0];
            string   tag            = imageParts[1];
            var      pullParameters = new ImagesCreateParameters
            {
                FromImage = fromImage,
                Tag       = tag
            };

            await Client.Images.CreateImageAsync(pullParameters, null, new Progress <JSONMessage>(), token);
        }
コード例 #19
0
        public async Task InitializeAsync()
        {
            var address = Environment.OSVersion.Platform == PlatformID.Unix
                                ? new Uri("unix:///var/run/docker.sock")
                                : new Uri("npipe://./pipe/docker_engine");

            var config = new DockerClientConfiguration(address);

            DockerClient = config.CreateClient();

            var imageParameters = new ImagesCreateParameters
            {
                FromImage = RedisImage,
                Tag       = "latest"
            };

            var images = await DockerClient.Images.ListImagesAsync(new ImagesListParameters { MatchName = RedisImage });

            if (!images.Any())
            {
                await DockerClient.Images.CreateImageAsync(imageParameters, null, IgnoreProgress.Forever);
            }

            var hostConfig = new HostConfig
            {
                PortBindings = new Dictionary <string, IList <PortBinding> >
                {
                    {
                        "6379/tcp",
                        new List <PortBinding> {
                            new PortBinding
                            {
                                HostPort = "9379"
                            }
                        }
                    }
                }
            };

            await DockerClient.Containers.CreateContainerAsync(
                new CreateContainerParameters
            {
                Image      = RedisImage,
                Name       = RedisContainer,
                HostConfig = hostConfig
            });

            await DockerClient.Containers.StartContainerAsync(RedisContainer, new ContainerStartParameters { });

            await Task.Delay(1000);
        }
コード例 #20
0
        private async Task PullImageToHost(DockerImage image)
        {
            var parameters = new ImagesCreateParameters
            {
                FromImage = image.ImageName,
                Tag       = image.ImageTag
            };

            var config = new AuthConfig();

            var progress = new Progress <JSONMessage>(stats => Console.WriteLine(stats.Status));

            await _dockerClient.Images.CreateImageAsync(parameters, config, progress, CancellationToken.None);
        }
コード例 #21
0
        public async Task ExecuteAsync(CancellationToken token)
        {
            string[] imageParts = this.combinedDockerConfig.Image.Split(':');
            string   image;
            string   tag;

            if (imageParts.Length > 1)
            {
                image = string.Join(":", imageParts.Take(imageParts.Length - 1));
                tag   = imageParts[imageParts.Length - 1];
            }
            else
            {
                image = imageParts[0];
                tag   = string.Empty;
            }

            var pullParameters = new ImagesCreateParameters
            {
                FromImage = image,
                Tag       = tag
            };

            try
            {
                await this.client.Images.CreateImageAsync(
                    pullParameters,
                    this.combinedDockerConfig.AuthConfig.OrDefault(),
                    new Progress <JSONMessage>(),
                    token);
            }
            catch (DockerApiException ex)
            {
                if (ex.StatusCode == HttpStatusCode.NotFound)
                {
                    throw new ImageNotFoundException(image, tag, ex.StatusCode.ToString(), ex);
                }
                else if (ex.StatusCode == HttpStatusCode.InternalServerError)
                {
                    throw new InternalServerErrorException(image, tag, ex.StatusCode.ToString(), ex);
                }

                // otherwise throw
                throw;
            }
        }
コード例 #22
0
ファイル: ImageController.cs プロジェクト: sc1994/Docker-GUI
        public async Task PullRemoteImage(ImagesCreateParameters input)
        {
            var progress = new Progress <JSONMessage>();

            progress.ProgressChanged += async(obj, message) =>
            {
                _log.LogInformation(JsonConvert.SerializeObject(message));
                await _hub.Clients.Group(Token).SendCoreAsync("pull", new[] { message });
            };
            await Client.Images.CreateImageAsync(
                input,
                new AuthConfig
            {
            },
                progress
                );
        }
コード例 #23
0
        public async Task PullImageAsync(string image)
        {
            var progress = new Progress <JSONMessage>();

            var parameters = new ImagesCreateParameters();

            parameters.FromImage = image;
            parameters.Tag       = "latest";
            parameters.FromSrc   = string.Empty;
            parameters.Repo      = string.Empty;

            var authConfig = new AuthConfig();

            authConfig.Email    = string.Empty;
            authConfig.Username = string.Empty;
            authConfig.Password = string.Empty;

            await _client.Images.CreateImageAsync(parameters, authConfig, progress);
        }
コード例 #24
0
        public async Task CreateAsync(IDockerImage image, IDockerRegistryAuthenticationConfiguration dockerRegistryAuthConfig, CancellationToken ct = default)
        {
            var createParameters = new ImagesCreateParameters
            {
                FromImage = image.FullName,
            };

            var authConfig = new AuthConfig
            {
                ServerAddress = dockerRegistryAuthConfig.RegistryEndpoint,
                Username      = dockerRegistryAuthConfig.Username,
                Password      = dockerRegistryAuthConfig.Password,
                IdentityToken = dockerRegistryAuthConfig.IdentityToken,
            };

            await this.Docker.Images.CreateImageAsync(createParameters, authConfig, this.traceProgress, ct)
            .ConfigureAwait(false);

            this.logger.DockerImageCreated(image);
        }
コード例 #25
0
        public async Task <ImageInspectResponse> CreateImageAsync(string image, string tag = "latest", string username = null, string password = null)
        {
            using var connection = await _dockerClient.ConnectAsync();

            var images = connection.Images;

            try
            {
                var imageParameters = new ImagesCreateParameters
                {
                    FromImage = image,
                    Tag       = tag ?? "latest"
                };
                var authConfig = new AuthConfig
                {
                    Username = username,
                    Password = password
                };

                var registry = image.Split('/').First();
                if (registry.Contains('.') && username != null && password != null)
                {
                    await _authService.AuthenticateAsync(registry, username, password);
                }

                await images.CreateImageAsync(imageParameters, authConfig, new Progress <JSONMessage>());

                _logger.LogInformation("Successfully finished pulling the image '{Image}'.", image);

                var inspectImage = await RetrieveImageAsync($"{image}:{imageParameters.Tag}");

                return(inspectImage);
            }
            catch (Exception ex)
            {
                _logger.LogWarning(ex, "Image '{Image}' could not be pulled successfully.", image);
                return(null);
            }
        }
コード例 #26
0
        private async Task DownloadImageAsync(IDockerClient dockerClient, VersionReference versionReference,
                                              CancellationToken cancellationToken)
        {
            var versionRequest = new GetImageDownloadInfoRequest()
            {
                Id = versionReference.Id
            };

            Logger.Information("Getting application download information for version {ImageId}...", versionReference.ImageId);

            //Get the download info
            var downloadInfo =
                await _deviceApiClient.ApplicationDownloadInfo.GetApplicationVersionDownloadInfo(versionRequest,
                                                                                                 cancellationToken);

            string fromImage = $"{downloadInfo.Registry}/{downloadInfo.Repository}:{downloadInfo.Name}";

            //Dowlnoad it!
            Logger.Information("Downloading with fromImage = '{FromImage}'...", fromImage);

            var imageCreateParameters = new ImagesCreateParameters
            {
                FromImage = fromImage
            };

            var authConfig = new AuthConfig()
            {
            };

            //Do the donwload!!!!!
            await dockerClient.Images.CreateImageAsync(
                imageCreateParameters,
                authConfig,
                new Progress <JSONMessage>(m => Console.WriteLine($"\tCreateImageProgress: {m.ProgressMessage}")),
                cancellationToken);

            Logger.Information("Application image {ImageId} downloaded.", versionReference.ImageId);
        }
コード例 #27
0
        private async Task PullImage(CancellationToken ct)
        {
            _logger.LogInformation("Pulling container image: {}", ImageName);
            var createParameters = new ImagesCreateParameters
            {
                FromImage = ImageName, Tag = ImageName.Split(':').Last(),
            };

            await DockerClient.Images.CreateImageAsync(
                createParameters,
                new AuthConfig(),
                new Progress <JSONMessage>(m =>
            {
                _logger.LogTrace("[{}] {}", m.Status, m.ProgressMessage);
            }),
                ct);

            // we should not catch exceptions thrown by inspect because the image is
            // expected to be available since we've just pulled it
            var image = await DockerClient.Images.InspectImageAsync(ImageName, ct);

            ImageId = image.ID;
        }
コード例 #28
0
        private async Task PullImageOntoHost(DockerImage image, HostType hostType)
        {
            Guard.Against.Null(image, nameof(image));
            Guard.Against.Null(hostType, nameof(hostType));

            var parameters = new ImagesCreateParameters
            {
                FromImage = image.ImageName,
                Tag       = image.ImageTag
            };

            var config = new AuthConfig();

            if (image.PrivateRepository)
            {
                config.Username      = image.PrivateRepositoryUsername;
                config.Password      = image.PrivateRepositoryPassword;
                config.ServerAddress = image.PrivateRepositoryHost;
            }

            var progress = new Progress <JSONMessage>(stats => Console.WriteLine(stats.Status));

            //Actually Pulldown image

            switch (hostType)
            {
            case HostType.Application:
                await _dockerAppClient.Images.CreateImageAsync(parameters, config, progress, CancellationToken.None);

                break;

            case HostType.Benchmark:
                await _dockerBenchmarkClient.Images.CreateImageAsync(parameters, config, progress, CancellationToken.None);

                break;
            }
        }
コード例 #29
0
        private async Task DownloadImage(CancellationToken cancellationToken)
        {
            var images = await _dockerClient.Images.ListImagesAsync(new ImagesListParameters {
                MatchName = ImageWithTag
            }, cancellationToken);

            if (images.Count == 0)
            {
                Log.Warning("Found 0 images matching {image}:{tag}. Downloading...", images.Count, _image, _tag);
                // No image found. Pulling latest ..
                var imagesCreateParameters = new ImagesCreateParameters {
                    FromImage = _image,
                    Tag       = _tag,
                };

                await _dockerClient
                .Images
                .CreateImageAsync(imagesCreateParameters, null, IgnoreProgress.Forever, cancellationToken);
            }
            else
            {
                Log.Information("Found {count} images matching {image}:{tag}", images.Count, _image, _tag);
            }
        }
コード例 #30
0
        public AdminTestsSetup()
        {
            var configDirectory =
                System.IO.Directory.CreateDirectory(
                    System.IO.Path.Combine(
                        System.IO.Path.GetTempPath(),
                        System.IO.Path.GetRandomFileName()));

            System.IO.File.WriteAllText(
                System.IO.Path.Combine(configDirectory.FullName, "rippled.cfg"),
                config);


            System.IO.File.WriteAllText(
                System.IO.Path.Combine(configDirectory.FullName, "validators.txt"),
                validators);

            Client = new DockerClientConfiguration(null, TimeSpan.FromMinutes(1.0)).CreateClient();

            // Pull the latest image
            var imagesCreateParameters = new ImagesCreateParameters
            {
                FromImage = "xrpllabsofficial/xrpld",
                Tag       = "latest"
            };
            var progress = new Progress <JSONMessage>();

            Client.Images.CreateImageAsync(imagesCreateParameters, null, progress).Wait();

            var createParameters = new CreateContainerParameters();

            createParameters.Volumes = new Dictionary <string, EmptyStruct>(new [] {
                KeyValuePair.Create("/config", new EmptyStruct()),
            });
            createParameters.Image      = imagesCreateParameters.FromImage + ":" + imagesCreateParameters.Tag;
            createParameters.HostConfig = new HostConfig {
                Binds           = new [] { configDirectory + ":/config:ro" },
                PublishAllPorts = true
            };
            createParameters.Cmd = new[] { "-a", "--start" };

            var container = Client.Containers.CreateContainerAsync(createParameters).Result;

            ID = container.ID;

            var startParameters = new ContainerStartParameters();
            var started         = Client.Containers.StartContainerAsync(ID, startParameters).Result;

            if (!started)
            {
                Dispose();
                throw new Exception("Could not start rippled container");
            }

            var inspect = Client.Containers.InspectContainerAsync(ID).Result;

            foreach (var port in inspect.NetworkSettings.Ports)
            {
                if (port.Key == "5005/tcp")
                {
                    HttpPort = port.Value[0].HostPort;
                }

                if (port.Key == "6006/tcp")
                {
                    WsPort = port.Value[0].HostPort;
                }
            }

            // Check we can ping the server
            for (int i = 0; i < 10; ++i)
            {
                var address    = new Uri("http://localhost:" + this.HttpPort);
                var httpClient = new HttpClient();
                httpClient.BaseAddress = address;
                var api = new JsonRpcApi(httpClient);
                try
                {
                    api.Ping().Wait(TimeSpan.FromSeconds(5.0));
                    break;
                }
                catch
                {
                    if (i == 9)
                    {
                        Dispose();
                        throw;
                    }
                    System.Threading.Thread.Sleep(500);
                }
                finally
                {
                    api.DisposeAsync().AsTask().Wait();
                }
            }
        }