private static bool TryGetDockerFromRegistryInstall(IFileSystem fs, IRegistryKey hklm, out LocalDocker docker)
        {
            using (var dockerRegKey = hklm.OpenSubKey(DockerRegistryPath)) {
                if (dockerRegKey != null)
                {
                    string[] subkeys = dockerRegKey.GetSubKeyNames();
                    foreach (var subKey in subkeys)
                    {
                        using (var key = dockerRegKey.OpenSubKey(subKey)) {
                            var isInstallKey = key.GetValueNames().Count(v => v.Equals("BinPath") || v.Equals("Version")) == 2;
                            if (isInstallKey)
                            {
                                var binPath     = ((string)key.GetValue("BinPath")).Trim('\"');
                                var commandPath = Path.Combine(binPath, DockerCommand);
                                if (fs.FileExists(commandPath))
                                {
                                    docker = new LocalDocker(binPath, commandPath);
                                    return(true);
                                }
                            }
                        }
                    }
                }
            }

            docker = null;
            return(false);
        }
示例#2
0
        protected override LocalDocker GetLocalDocker()
        {
            _docker = _docker ?? _dockerFinder.GetLocalDocker();
            _dockerFinder.CheckIfServiceIsRunning();

            return(_docker);
        }
示例#3
0
        public LocalDocker GetLocalDocker()
        {
            const string dockerPath = "/usr/bin/docker";
            var          packages   = InstalledPackageInfo.GetPackages(_fs);
            var          dockerPkgs = packages
                                      .Where(pkg => pkg.PackageName.EqualsIgnoreCase(DockerCePackageName) || pkg.PackageName.EqualsIgnoreCase(DockerEePackageName))
                                      .ToList();

            if (dockerPkgs.Any())
            {
                var pkg   = dockerPkgs.First();
                var files = pkg.GetPackageFiles(_fs).Where(f => f.Equals(dockerPath));
                if (files.Any())
                {
                    var docker = new LocalDocker(Path.GetDirectoryName(dockerPath), dockerPath);
                    if (!_fs.FileExists(docker.DockerCommandPath))
                    {
                        throw new ContainerServiceNotInstalledException(Resources.Error_NoDockerCommand.FormatInvariant(docker.DockerCommandPath));
                    }

                    return(docker);
                }
            }

            throw new ContainerServiceNotInstalledException(Resources.Error_DockerNotFound.FormatInvariant(DockerCePackageName, DockerEePackageName));
        }
        public LocalDocker GetLocalDocker()
        {
            LocalDocker docker = null;

            using (var hklm64 = _rs.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64)) {
                if (!TryGetDockerFromRegistryInstall(_fs, hklm64, out docker) &&
                    !TryGetDockerFromServiceInstall(_fs, hklm64, out docker) &&
                    !TryGetDockerFromProgramFiles(_fs, out docker))
                {
                    throw new ContainerServiceNotInstalledException(Resources.Error_DockerNotFound.FormatInvariant(DockerRegistryPath));
                }
            }

            if (!_fs.FileExists(docker.DockerCommandPath))
            {
                throw new ContainerServiceNotInstalledException(Resources.Error_NoDockerCommand.FormatInvariant(docker.DockerCommandPath));
            }

            return(docker);
        }
        private static bool TryGetDockerFromProgramFiles(IFileSystem fs, out LocalDocker docker)
        {
            string[] envVars = { "ProgramFiles", "ProgramFiles(x86)", "ProgramW6432" };
            foreach (var envVar in envVars)
            {
                var progFiles = Environment.GetEnvironmentVariable(envVar);
                if (!string.IsNullOrWhiteSpace(progFiles))
                {
                    var basePath    = Path.Combine(progFiles, "Docker", "Docker");
                    var binPath     = Path.Combine(basePath, "resources", "bin");
                    var commandPath = Path.Combine(binPath, DockerCommand);
                    if (fs.FileExists(commandPath))
                    {
                        docker = new LocalDocker(binPath, commandPath);
                        return(true);
                    }
                }
            }

            docker = null;
            return(false);
        }
        private static bool TryGetDockerFromServiceInstall(IFileSystem fs, IRegistryKey hklm, out LocalDocker docker)
        {
            using (var dockerRegKey = hklm.OpenSubKey(DockerRegistryPath2)) {
                if (dockerRegKey != null)
                {
                    var valueNames = dockerRegKey.GetValueNames();
                    if (valueNames.Contains("ImagePath"))
                    {
                        var comPath     = ((string)dockerRegKey.GetValue("ImagePath")).Trim('\"');
                        var basePath    = Path.GetDirectoryName(comPath);
                        var binPath     = Path.Combine(basePath, "resources", "bin");
                        var commandPath = Path.Combine(binPath, DockerCommand);
                        if (fs.FileExists(commandPath))
                        {
                            docker = new LocalDocker(binPath, commandPath);
                            return(true);
                        }
                    }
                }
            }

            docker = null;
            return(false);
        }
示例#7
0
 protected override LocalDocker GetLocalDocker()
 {
     _docker = _docker ?? _dockerFinder.GetLocalDocker();
     return(_docker);
 }