Beispiel #1
0
        public async Task CleanImageDownloadTest()
        {
            var svc = new WindowsDockerService(_services);

            var    param     = new ContainerCreateParameters("hello-world", "latest");
            string imageName = $"{param.Image}:{param.Tag}";

            await DeleteImageAsync(imageName);

            var images = await svc.ListImagesAsync(false, CancellationToken.None);

            images.Should().NotContain(c => c.Name == param.Image && c.Tag == param.Tag);

            var container = await svc.CreateContainerAsync(param, CancellationToken.None);

            await svc.StartContainerAsync(container.Id, CancellationToken.None);

            var images2 = await svc.ListImagesAsync(false, CancellationToken.None);

            images2.Should().Contain(c => c.Name == param.Image && c.Tag == param.Tag);

            await svc.StopContainerAsync(container.Id, CancellationToken.None);

            await svc.DeleteContainerAsync(container.Id, CancellationToken.None);

            var allContainers = await svc.ListContainersAsync(true, CancellationToken.None);

            allContainers.Should().NotContain(c => c.Id == container.Id);

            await DeleteImageAsync(imageName);
        }
Beispiel #2
0
        public async Task <IContainer> CreateContainerAsync(ContainerCreateParameters createParams, CancellationToken ct)
        {
            await TaskUtilities.SwitchToBackgroundThread();

            if (createParams.ImageSourceCredentials != null)
            {
                await RepositoryLoginAsync(createParams.ImageSourceCredentials, ct);
            }
            try {
                await PullImageAsync(Invariant($"{createParams.Image}:{createParams.Tag}"), ct);

                string createOptions = Invariant($"{createParams.StartOptions} {createParams.Image}:{createParams.Tag} {createParams.Command}");
                var    containerId   = await CreateContainerAsync(createOptions, ct);

                if (string.IsNullOrEmpty(containerId))
                {
                    throw new ContainerException(Resources.Error_ContainerIdInvalid.FormatInvariant(containerId));
                }
                return(await GetContainerAsync(containerId, ct));
            } catch (ContainerException cex) {
                throw cex;
            } finally {
                if (createParams.ImageSourceCredentials != null)
                {
                    await RepositoryLogoutAsync(createParams.ImageSourceCredentials, ct);
                }
            }
        }
Beispiel #3
0
        public async Task CreateAndDeleteContainerTest()
        {
            var svc       = new WindowsDockerService(_services);
            var param     = new ContainerCreateParameters("docker.io/kvnadig/rtvs-linux", "latest");
            var container = await svc.CreateContainerAsync(param, CancellationToken.None);

            var container2 = await svc.GetContainerAsync(container.Id, CancellationToken.None);

            container.Id.Should().Be(container2.Id);
            await svc.DeleteContainerAsync(container.Id, CancellationToken.None);

            var containers = await svc.ListContainersAsync(true, CancellationToken.None);

            containers.Should().NotContain(c => c.Id == container.Id);
        }
Beispiel #4
0
        public async Task StartStopContainerTest()
        {
            var svc       = new WindowsDockerService(_services);
            var param     = new ContainerCreateParameters("docker.io/kvnadig/rtvs-linux", "latest");
            var container = await svc.CreateContainerAsync(param, CancellationToken.None);

            await svc.StartContainerAsync(container.Id, CancellationToken.None);

            var runningContainers = await svc.ListContainersAsync(false, CancellationToken.None);

            runningContainers.Should().Contain(c => c.Id == container.Id);

            await svc.StopContainerAsync(container.Id, CancellationToken.None);

            var runningContainers2 = await svc.ListContainersAsync(false, CancellationToken.None);

            runningContainers2.Should().NotContain(c => c.Id == container.Id);

            await svc.DeleteContainerAsync(container.Id, CancellationToken.None);

            var allContainers = await svc.ListContainersAsync(true, CancellationToken.None);

            allContainers.Should().NotContain(c => c.Id == container.Id);
        }