@Test public void isContainerRunning() { DockerTestHelper.assumeDockerIsPresent(); boolean containerRunning = Dockers.isContainerRunning("nosuchcontainer"); assertThat(containerRunning, is(false)); }
static public boolean isContainerRunning( String name) { final String output = new LocalExec(Contexts.currentContext()) .command("docker") .args("ps") .runCaptureOutput() .asString() .trim(); String[] lines = output.split("\n"); if (lines == null || lines.length < 1) { throw new BlazeException("No docker ps output detected"); } String headerLine = lines[0]; final List<HeaderToken> headers = HeaderToken.parseHeaderLine(headerLine); final List<ProcessRow> processes = new ArrayList<>(); for (int i = 1; i < lines.length; i++) { String line = lines[i]; ProcessRow row = new ProcessRow(); for (int j = 0; j < headers.size(); j++) { HeaderToken header = headers.get(j); int end = ((j+1) < headers.size()) ? headers.get(j+1).getStart() : line.length(); String value = line.substring(header.getStart(), end); switch(header.getName().toLowerCase()) { case "container id": row.setContainerId(value); break; case "status": row.setStatus(value); break; case "names": row.setNames(value); break; } } processes.add(row); } return processes.stream() .filter(v -> v.getNames().toLowerCase().contains(name.toLowerCase())) .anyMatch(v -> v.getStatus().toLowerCase().contains("up")); }
Dockers { static public boolean isContainerRunning( String name) { final String output = new LocalExec(Contexts.currentContext()) .command("docker") .args("ps") .runCaptureOutput() .asString() .trim(); String[] lines = output.split("\n"); if (lines == null || lines.length < 1) { throw new BlazeException("No docker ps output detected"); } String headerLine = lines[0]; final List<HeaderToken> headers = HeaderToken.parseHeaderLine(headerLine); final List<ProcessRow> processes = new ArrayList<>(); for (int i = 1; i < lines.length; i++) { String line = lines[i]; ProcessRow row = new ProcessRow(); for (int j = 0; j < headers.size(); j++) { HeaderToken header = headers.get(j); int end = ((j+1) < headers.size()) ? headers.get(j+1).getStart() : line.length(); String value = line.substring(header.getStart(), end); switch(header.getName().toLowerCase()) { case "container id": row.setContainerId(value); break; case "status": row.setStatus(value); break; case "names": row.setNames(value); break; } } processes.add(row); } return processes.stream() .filter(v -> v.getNames().toLowerCase().contains(name.toLowerCase())) .anyMatch(v -> v.getStatus().toLowerCase().contains("up")); } }
Dockers { static public boolean isContainerRunning( String name) { final String output = new LocalExec(Contexts.currentContext()) .command("docker") .args("ps") .runCaptureOutput() .asString() .trim(); String[] lines = output.split("\n"); if (lines == null || lines.length < 1) { throw new BlazeException("No docker ps output detected"); } String headerLine = lines[0]; final List<HeaderToken> headers = HeaderToken.parseHeaderLine(headerLine); final List<ProcessRow> processes = new ArrayList<>(); for (int i = 1; i < lines.length; i++) { String line = lines[i]; ProcessRow row = new ProcessRow(); for (int j = 0; j < headers.size(); j++) { HeaderToken header = headers.get(j); int end = ((j+1) < headers.size()) ? headers.get(j+1).getStart() : line.length(); String value = line.substring(header.getStart(), end); switch(header.getName().toLowerCase()) { case "container id": row.setContainerId(value); break; case "status": row.setStatus(value); break; case "names": row.setNames(value); break; } } processes.add(row); } return processes.stream() .filter(v -> v.getNames().toLowerCase().contains(name.toLowerCase())) .anyMatch(v -> v.getStatus().toLowerCase().contains("up")); }  }
Dockers { static public boolean isContainerRunning( String name) { final String output = new LocalExec(Contexts.currentContext()) .command("docker") .args("ps") .runCaptureOutput() .asString() .trim(); String[] lines = output.split("\n"); if (lines == null || lines.length < 1) { throw new BlazeException("No docker ps output detected"); } String headerLine = lines[0]; final List<HeaderToken> headers = HeaderToken.parseHeaderLine(headerLine); final List<ProcessRow> processes = new ArrayList<>(); for (int i = 1; i < lines.length; i++) { String line = lines[i]; ProcessRow row = new ProcessRow(); for (int j = 0; j < headers.size(); j++) { HeaderToken header = headers.get(j); int end = ((j+1) < headers.size()) ? headers.get(j+1).getStart() : line.length(); String value = line.substring(header.getStart(), end); switch(header.getName().toLowerCase()) { case "container id": row.setContainerId(value); break; case "status": row.setStatus(value); break; case "names": row.setNames(value); break; } } processes.add(row); } return processes.stream() .filter(v -> v.getNames().toLowerCase().contains(name.toLowerCase())) .anyMatch(v -> v.getStatus().toLowerCase().contains("up")); }  static DockerConnect dockerConnect(String uri); static DockerConnect dockerConnect(URI uri); static DockerConnect dockerConnect(MutableUri uri); static boolean isContainerRunning(
            String name); }
Dockers { static public boolean isContainerRunning( String name) { final String output = new LocalExec(Contexts.currentContext()) .command("docker") .args("ps") .runCaptureOutput() .asString() .trim(); String[] lines = output.split("\n"); if (lines == null || lines.length < 1) { throw new BlazeException("No docker ps output detected"); } String headerLine = lines[0]; final List<HeaderToken> headers = HeaderToken.parseHeaderLine(headerLine); final List<ProcessRow> processes = new ArrayList<>(); for (int i = 1; i < lines.length; i++) { String line = lines[i]; ProcessRow row = new ProcessRow(); for (int j = 0; j < headers.size(); j++) { HeaderToken header = headers.get(j); int end = ((j+1) < headers.size()) ? headers.get(j+1).getStart() : line.length(); String value = line.substring(header.getStart(), end); switch(header.getName().toLowerCase()) { case "container id": row.setContainerId(value); break; case "status": row.setStatus(value); break; case "names": row.setNames(value); break; } } processes.add(row); } return processes.stream() .filter(v -> v.getNames().toLowerCase().contains(name.toLowerCase())) .anyMatch(v -> v.getStatus().toLowerCase().contains("up")); }  static DockerConnect dockerConnect(String uri); static DockerConnect dockerConnect(URI uri); static DockerConnect dockerConnect(MutableUri uri); static boolean isContainerRunning(
            String name);  }