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; }
public ContainerPool(IClientFacade client, INetworkSetup network) { if (client is null) { throw new ArgumentNullException(nameof(client)); } _client = client; _network = network; }
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); } } }
public static NetworkingConfig MapFrom(INetworkSetup setup, string networkId) { if (setup is null) { throw new ArgumentNullException(nameof(setup)); } if (string.IsNullOrEmpty(networkId)) { throw new ArgumentNullException(nameof(networkId)); } return(new NetworkingConfig { EndpointsConfig = new Dictionary <string, EndpointSettings> { { setup.Name, new EndpointSettings { NetworkID = networkId } } } }); }