示例#1
0
        public DockerHostService(string name, bool isNative, bool stopWhenDisposed = false, string dockerUri = null,
                                 string certificatePath = null, bool isWindowsHost = false)
            : base(name)
        {
            _isWindowsHost    = isWindowsHost;
            _stopWhenDisposed = stopWhenDisposed;

            IsNative = isNative;
            if (IsNative)
            {
                var uri      = dockerUri ?? DockerUri.GetDockerHostEnvronmentPathOrDefault();
                var certPath = certificatePath ?? Environment.GetEnvironmentVariable(DockerCertPath);

                if (!string.IsNullOrEmpty(certPath))
                {
                    Certificates = new CertificatePaths
                    {
                        CaCertificate     = Path.Combine(certPath, DefaultCaCertName),
                        ClientCertificate = Path.Combine(certPath, DefaultClientCertName),
                        ClientKey         = Path.Combine(certPath, DefaultClientKeyName)
                    }
                }
                ;

                Host       = string.IsNullOrEmpty(uri) ? null : new DockerUri(uri);
                RequireTls = Environment.GetEnvironmentVariable(DockerTlsVerify) == "1";
                State      = ServiceRunningState.Running;
                return;
            }

            // Machine - do inspect & get url
            MachineSetup(name);
        }