Exemple #1
0
        public IContainerService Create(string image, bool forcePull, ContainerCreateParams prms = null,
                                        bool stopOnDispose = true, bool deleteOnDispose = true, bool deleteVolumeOnDispose = false,
                                        bool deleteNamedVolumeOnDispose = false,
                                        string command = null, string[] args = null)
        {
            if (forcePull)
            {
                var force = Host.Pull(image, Certificates);
                if (!force.Success)
                {
                    throw new FluentDockerException($"Could not pull image ${image}. Result: {force}");
                }
            }

            var res = Host.Create(image, command, args, prms, Certificates);

            if (!res.Success || 0 == res.Data.Length)
            {
                throw new FluentDockerException(
                          $"Could not create Service from {image} with command {command}, args {args}, and parameters {prms}. Result: {res}");
            }

            var config = Host.InspectContainer(res.Data, Certificates);

            if (!config.Success)
            {
                throw new FluentDockerException(
                          $"Could not return service for docker id {res.Data} - Container was created, you have to manually delete it or do a Ls");
            }

            return(new DockerContainerService(config.Data.Name, res.Data, Host, config.Data.State.ToServiceState(),
                                              Certificates, stopOnDispose, deleteOnDispose, deleteVolumeOnDispose, deleteNamedVolumeOnDispose,
                                              _isWindowsHost));
        }
Exemple #2
0
        public static CommandResponse <string> Create(this DockerUri host, string image, string command = null,
                                                      string[] args = null, ContainerCreateParams prms = null, ICertificatePaths certificates = null)
        {
            var certArgs = host.RenderBaseArgs(certificates);

            var arg = $"{certArgs} create";

            if (null != prms)
            {
                arg += " " + prms;
            }

            arg += " " + image;

            if (!string.IsNullOrEmpty(command))
            {
                arg += $" {command}";
            }

            if (null != args && 0 != args.Length)
            {
                arg += " " + string.Join(" ", args);
            }

            return
                (new ProcessExecutor <SingleStringResponseParser, string>(
                     "docker".ResolveBinary(),
                     arg).Execute());
        }
Exemple #3
0
        public void ContainerIsolationGeneratesRuntimeOption(ContainerIsolationTechnology isolationTechnology, string expectedIsolationParameter)
        {
            var prms = new ContainerCreateParams {
                Isolation = isolationTechnology
            };
            var opts = prms.ToString();

            Assert.IsTrue(opts.Contains($" --isolation {expectedIsolationParameter}"));
        }
Exemple #4
0
        public void NvidiaRuntimeGeneratesRuntimeOption()
        {
            var prms = new ContainerCreateParams {
                Runtime = ContainerRuntime.Nvidia
            };
            var opts = prms.ToString();

            Assert.IsTrue(opts.Contains(" --runtime=nvidia"));
        }
Exemple #5
0
        public static CommandResponse <string> Run(this DockerUri host, string image, ContainerCreateParams args = null,
                                                   ICertificatePaths certificates = null)
        {
            var arg = $"{host.RenderBaseArgs(certificates)} run -d";

            if (null != args)
            {
                arg += " " + args;
            }

            arg += " " + image;

            return
                (new ProcessExecutor <SingleStringResponseParser, string>(
                     "docker".ResolveBinary(),
                     arg).Execute());
        }
 public ContainerBuilderConfig()
 {
     CreateParams = new ContainerCreateParams();
 }