예제 #1
0
        //[Test]
        public void TestCreateBashContainer()
        {
            // Arrange
            var containerConfig = new ContainerConfig(image: "bash");
            var name            = "bash_instance";

            // Act
            var containerCreateResponse = _containerApi.ContainerCreate(containerConfig, name);

            // Assert
            Assert.NotNull(containerCreateResponse);
            Assert.NotNull(containerCreateResponse.Id);
        }
예제 #2
0
        /// <summary>
        /// Instantiates, Starts, and Gets Container details through Docker API
        /// </summary>
        /// <returns>Instance of <see cref="IRunspaceInfo"/> for the started Runspace Container.</returns>
        public IRunspaceInfo StartCreate()
        {
            IRunspaceInfo result          = null;
            const long    CPUsCount       = 1;
            const long    BytesInMegaByte = 1048576;
            var           containerConfig = new ContainerConfig(
                image: _runspaceContainerCreateSpec.ImageName,
                hostConfig: new HostConfig(
                    networkMode: _runspaceContainerCreateSpec.NetworkName,
                    cpuCount: CPUsCount,
                    restartPolicy: new RestartPolicy(RestartPolicy.NameEnum.Empty),
                    memory: BytesInMegaByte * _runspaceContainerCreateSpec.RunspaceContainerMemoryLimitMB));

            ContainerCreateResponse runspaceContainerInstance;

            try {
                // Create Runspace Container Instance
                runspaceContainerInstance = _containerApi.ContainerCreate(containerConfig);

                // Start Runspace Container
                _containerApi.ContainerStart(runspaceContainerInstance.Id);

                result = Get(runspaceContainerInstance.Id);
            } catch (ApiException dockerApiException) {
                result = DockerRunspaceInfo.FromRunspaceProviderError(
                    new RunspaceProviderException(
                        Resources.Resources.DockerRunspaceProvider_Create_StartContainerDockerAPIFail,
                        dockerApiException));
            }

            try {
                if (_testConnectionToContainerOnCreate)
                {
                    // Ensure Container is accessible over the network after creation
                    EnsureRunspaceEndpointIsAccessible(result);
                }
            } catch (RunspaceProviderException exception) {
                // Kill the container that is not accessible, otherwise it will leak
                try {
                    if (result.Id != null)
                    {
                        Kill(result.Id);
                    }
                } catch (RunspaceProviderException) {}

                result = DockerRunspaceInfo.FromRunspaceProviderError(exception);
            }

            return(result);
        }