Пример #1
0
        private string ExtractRunCommandFromContainer(SshClient sshClient, string containerIdOrName)
        {
            var runTplExists = CheckIfFileExists(sshClient, "run.tpl");

            if (!runTplExists)
            {
                CreateRunTpl(sshClient);
            }

            var result = sshClient.RunShellCommand($@"docker inspect --format ""$(<run.tpl)"" {containerIdOrName}");

            return(result);
        }
Пример #2
0
        private Dictionary <string, string> GetContainersAndImages(SshClient sshClient)
        {
            var result = sshClient.RunShellCommand(@"docker ps -a --format=""{{.ID}}|{{.Image}}""");
            var lines  = result.Split('\n');

            var containersAndImages = lines.Select(x =>
            {
                var splittedVar = x.Split('|');
                return(new KeyValuePair <string, string>(splittedVar[0], splittedVar[1]));
            }).ToDictionary(x => x.Key, x => x.Value);

            return(containersAndImages);
        }
Пример #3
0
 private void RemoveContainer(SshClient sshClient, string containerId)
 {
     sshClient.RunShellCommand($"docker rm {containerId}");
 }
Пример #4
0
 private void StopContainer(SshClient sshClient, string containerId, int timeoutInSeconds = 500)
 {
     sshClient.RunShellCommand(@$ "docker stop --time {timeoutInSeconds} {containerId}");
 }
Пример #5
0
        private bool CheckIfFileExists(SshClient sshClient, string fileName)
        {
            var result = sshClient.RunShellCommand($@"if [ -e {fileName} ]; then echo ""ok""; else echo ""nok""; fi");

            return(result.Trim() == "ok");
        }