public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
        {
            if (forceResolve)
            {
                _binaryResolver = new DockerBinariesResolver(_sudoMechanism, _sudoPassword);
            }

            var binary = _binaryResolver.Resolve(dockerCommand, preferMachine);

            if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None)
            {
                return(binary.FqPath);
            }

            string cmd;

            if (binary.Sudo == SudoMechanism.NoPassword)
            {
                cmd = $"sudo {binary.FqPath}";
            }
            else
            {
                cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}";
            }

            return(cmd);
        }
        public static string ResolveBinary(this string dockerCommand, DockerBinariesResolver resolver, bool preferMachine = false)
        {
            var binary = resolver.Resolve(dockerCommand, preferMachine);

            if (FdOs.IsWindows() || binary.Sudo == SudoMechanism.None)
            {
                return(binary.FqPath);
            }

            string cmd;

            if (binary.Sudo == SudoMechanism.NoPassword)
            {
                cmd = $"sudo {binary.FqPath}";
            }
            else
            {
                cmd = $"echo {binary.SudoPassword} | sudo -S {binary.FqPath}";
            }

            if (string.IsNullOrEmpty(cmd))
            {
                if (!string.IsNullOrEmpty(dockerCommand) && dockerCommand.ToLower() == "docker-machine")
                {
                    throw new FluentDockerException(
                              $"Could not find {dockerCommand} make sure it is on your path. From 2.2.0 you have to seprately install it via https://github.com/docker/machine/releases");
                }

                throw new FluentDockerException($"Could not find {dockerCommand}, make sure it is on your path.");
            }

            return(cmd);
        }
Exemple #3
0
        public static string ResolveBinary(this string dockerCommand, bool preferMachine = false, bool forceResolve = false)
        {
            if (forceResolve)
            {
                _binaryResolver = new DockerBinariesResolver();
            }

            return(_binaryResolver.Resolve(dockerCommand, preferMachine).FqPath);
        }