public async Task <string> RunAsync(ITestcontainersConfiguration configuration, CancellationToken ct = default) { var converter = new TestcontainersConfigurationConverter(configuration); var hostConfig = new HostConfig { PortBindings = converter.PortBindings, Mounts = converter.Mounts, }; var createParameters = new CreateContainerParameters { Image = configuration.Image.FullName, Name = configuration.Name, WorkingDir = configuration.WorkingDirectory, Entrypoint = converter.Entrypoint, Cmd = converter.Command, Env = converter.Environments, Labels = converter.Labels, ExposedPorts = converter.ExposedPorts, HostConfig = hostConfig, }; var id = (await this.Docker.Containers.CreateContainerAsync(createParameters, ct) .ConfigureAwait(false)).ID; Logger.LogInformation("Container {id} created", id); return(id); }
public async Task <string> RunAsync(TestcontainersConfiguration config, CancellationToken cancellationToken = default) { var image = config.Container.Image; var pullImageTask = MetaDataClientImages.Instance.ExistsWithNameAsync(image).ContinueWith(async imageExists => { if (!await imageExists) { // await ... does not work here, the image will not be pulled. Docker.Images.CreateImageAsync(new ImagesCreateParameters { FromImage = image }, null, DebugProgress.Instance, cancellationToken).GetAwaiter().GetResult(); } }); var name = config.Container.Name; var workingDir = config.Container.WorkingDirectory; var converter = new TestcontainersConfigurationConverter(config); var entrypoint = converter.Entrypoint; var cmd = converter.Command; var env = converter.Environments; var labels = converter.Labels; var exposedPorts = converter.ExposedPorts; var portBindings = converter.PortBindings; var mounts = converter.Mounts; var hostConfig = new HostConfig { PortBindings = portBindings, Mounts = mounts, }; var createParameters = new CreateContainerParameters { Image = image, Name = name, WorkingDir = workingDir, Entrypoint = entrypoint, Env = env, Labels = labels, Cmd = cmd, ExposedPorts = exposedPorts, HostConfig = hostConfig, }; await pullImageTask; return((await Docker.Containers.CreateContainerAsync(createParameters, cancellationToken)).ID); }
public async Task <string> RunAsync(ITestcontainersConfiguration configuration, CancellationToken ct = default) { var converter = new TestcontainersConfigurationConverter(configuration); var hostConfig = new HostConfig { AutoRemove = configuration.AutoRemove.HasValue && configuration.AutoRemove.Value, Privileged = configuration.Privileged.HasValue && configuration.Privileged.Value, PortBindings = converter.PortBindings, Mounts = converter.Mounts, }; var networkingConfig = new NetworkingConfig { EndpointsConfig = converter.Networks, }; var createParameters = new CreateContainerParameters { Image = configuration.Image.FullName, Name = configuration.Name, Hostname = configuration.Hostname, WorkingDir = configuration.WorkingDirectory, Entrypoint = converter.Entrypoint, Cmd = converter.Command, Env = converter.Environments, Labels = converter.Labels, ExposedPorts = converter.ExposedPorts, HostConfig = hostConfig, NetworkingConfig = networkingConfig, }; var id = (await this.Docker.Containers.CreateContainerAsync(createParameters, ct) .ConfigureAwait(false)).ID; this.logger.DockerContainerCreated(id); return(id); }