private async Task StartContainer(string containerId) { await TaskUtil.TimedExecute( async() => await _dockerClient.Containers.StartContainerAsync(containerId, DefaultStartParameters), _logger, MetricConstants.ContainerStats, MetricConstants.ContainerStartTime); _logger.LogInformation($"Container {containerId} start completed."); }
private async Task <string> CreateContainer( string imageName, IList <string> environmentVariables, IList <string> volumeBindings, IList <PortMapping> portMappings, IList <string> startCmd, HostConfig hostConfigOverrides, string workingDirectory) { HostConfig hostConfig = hostConfigOverrides ?? new HostConfig(); hostConfig.NetworkMode = SessionHostContainerConfiguration.DockerNetworkName; hostConfig.Binds = volumeBindings; hostConfig.PortBindings = portMappings?.ToDictionary(p => $"{p.GamePort.Number}/{p.GamePort.Protocol}", p => (IList <PortBinding>)(new List <PortBinding>() { new PortBinding() { HostPort = $"{p.NodePort}/{p.GamePort.Protocol}" } })); if (hostConfig.LogConfig == null) { hostConfig.LogConfig = new LogConfig(); hostConfig.LogConfig.Type = "json-file"; hostConfig.LogConfig.Config = new Dictionary <string, string>() { { "max-size", "200m" } }; } CreateContainerParameters containerParams = new CreateContainerParameters { Image = imageName, Env = environmentVariables, ExposedPorts = portMappings?.ToDictionary(p => $"{p.GamePort.Number}/{p.GamePort.Protocol}", p => new EmptyStruct()), HostConfig = hostConfig, WorkingDir = workingDirectory, Cmd = startCmd }; _logger.LogInformation($"Creating container. Image='{imageName}'"); CreateContainerResponse response = await TaskUtil.TimedExecute( async() => await _dockerClient.Containers.CreateContainerAsync(containerParams).ConfigureAwait(false), _logger, MetricConstants.ContainerStats, MetricConstants.ContainerCreationTime); _logger.LogInformation($"Created a container with session host id: {response.ID}"); return(response.ID); }