Exemple #1
0
        protected async Task CreateContainerAsync(IClientFacade client, INetworkSetup network)
        {
            var container = await client.GetExistingContainerAsync(Options.Name);

            ContainerId = container is null
                ? await client.CreateContainerAsync(Options, network)
                : container.Id;
        }
Exemple #2
0
        public virtual async Task ConfigureAsync(IClientFacade client, INetworkSetup network)
        {
            try
            {
                if (network != default)
                {
                    await network.CreateNetworkAsync();
                }

                var existingContainer = await client.GetExistingContainerAsync(Options.Name);

                if (existingContainer == default)
                {
                    await DownloadImageAsync(client);
                    await CreateContainerAsync(client, network);
                }
                else
                {
                    ContainerId = existingContainer.Id;
                }

                if (!existingContainer?.IsRunning ?? true)
                {
                    await client.StartContainerAsync(ContainerId);
                }

                await WaitContainerAsync();

                DefineAsReady();
            }
            catch (DockerApiException ex)
            {
                if (ex.Message.Contains("code=Conflict"))
                {
                    await WaitContainerAsync();

                    DefineAsReady();
                }
                else
                {
                    throw new InvalidOperationException("Something unexpected happened during image setup.", ex);
                }
            }
        }