/// <summary> /// /// </summary> /// <param name="dockerClient"></param> /// <param name="imageId">The id of the new agent image.</param> /// <param name="existingContainerName">The name of the existing container</param> /// <param name="incomingContainerName">The name of the new container to create.</param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task <CreateContainerResponse> CreateContainerForUpdateAsync( IDockerClient dockerClient, string imageId, string existingContainerName, string incomingContainerName, CancellationToken cancellationToken) { var existingContainer = await dockerClient.GetContainerByName(existingContainerName, cancellationToken); if (existingContainer == null) { string message = $"Unable to find container '{existingContainerName}'"; Console.Error.WriteLine(message); throw new Exception(message); } //Get the existing container var existingContainerInspection = await dockerClient.Containers.InspectContainerAsync(existingContainer.ID, cancellationToken); if (existingContainerInspection == null) { string message = $"Unable to inspect container '{existingContainer.ID}'"; Console.Error.WriteLine(message); throw new Exception(message); } var createContainerParameters = new CreateContainerParameters { Image = imageId, Name = incomingContainerName, HostConfig = existingContainerInspection.HostConfig, Env = existingContainerInspection.Config.Env }; //Create it!!!! return(await dockerClient.Containers.CreateContainerAsync(createContainerParameters, cancellationToken)); }
public async Task <string> GetCurrentVersionAsync(CancellationToken cancellationToken = new CancellationToken()) { var container = await _dockerClient.GetContainerByName(DockerContainerNames.Application, cancellationToken); return(container?.ImageID); }