Java Code Examples for com.github.dockerjava.api.command.ListContainersCmd#exec()
The following examples show how to use
com.github.dockerjava.api.command.ListContainersCmd#exec() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContainerUtil.java From presto with Apache License 2.0 | 6 votes |
public static void killContainers(DockerClient dockerClient, Function<ListContainersCmd, ListContainersCmd> filter) { while (true) { ListContainersCmd listContainersCmd = filter.apply(dockerClient.listContainersCmd() .withShowAll(true)); List<Container> containers = listContainersCmd.exec(); if (containers.isEmpty()) { break; } for (Container container : containers) { try { dockerClient.removeContainerCmd(container.getId()) .withForce(true) .exec(); } catch (ConflictException | NotFoundException ignored) { } } } }
Example 2
Source File: DockerHelper.java From dynamo-cassandra-proxy with Apache License 2.0 | 6 votes |
private Container searchContainer(String name) { ListContainersCmd listContainersCmd = dockerClient.listContainersCmd().withStatusFilter(List.of("running")); listContainersCmd.getFilters().put("name", Arrays.asList(name)); List<Container> runningContainers = null; try { runningContainers = listContainersCmd.exec(); } catch (Exception e) { e.printStackTrace(); logger.error("Unable to contact docker, make sure docker is up and try again."); System.exit(1); } if (runningContainers.size() >= 1) { //Container test = runningContainers.get(0); logger.info(String.format("The container %s is already running", name)); return runningContainers.get(0); } return null; }
Example 3
Source File: ListContainersWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); String statusFilter = (String) workItem.getParameter("StatusFilter"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } ListContainersCmd listContainersCmd = dockerClient.listContainersCmd() .withShowAll(true).withShowSize(true); if (statusFilter != null && statusFilter.trim().length() > 0) { listContainersCmd = listContainersCmd.withStatusFilter(statusFilter); } List<Container> containers = listContainersCmd.exec(); results.put(RESULTS_DOCUMENT, containers); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Unable to get list of containers: " + e.getMessage()); handleException(e); } }