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); }
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); }
private void RemoveContainer(SshClient sshClient, string containerId) { sshClient.RunShellCommand($"docker rm {containerId}"); }
private void StopContainer(SshClient sshClient, string containerId, int timeoutInSeconds = 500) { sshClient.RunShellCommand(@$ "docker stop --time {timeoutInSeconds} {containerId}"); }
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"); }