本文整理匯總了Java中com.spotify.docker.client.DockerClient.listContainers方法的典型用法代碼示例。如果您正苦於以下問題:Java DockerClient.listContainers方法的具體用法?Java DockerClient.listContainers怎麽用?Java DockerClient.listContainers使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.spotify.docker.client.DockerClient
的用法示例。
在下文中一共展示了DockerClient.listContainers方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: refreshAll
import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
@Override
public void refreshAll(PluginRequest pluginRequest) throws Exception {
if (!refreshed) {
DockerClient docker = docker(pluginRequest.getPluginSettings());
List<Container> containers = docker.listContainers(DockerClient.ListContainersParam.withLabel(Constants.CREATED_BY_LABEL_KEY, Constants.PLUGIN_ID));
for (Container container : containers) {
register(DockerContainer.fromContainerInfo(docker.inspectContainer(container.id())));
}
refreshed = true;
}
}
示例2: removeContainers
import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
private void removeContainers(DockerClient dockerClient, String imageName) throws DockerException, InterruptedException {
log.debug("about to cleanup all containers created from image {}", imageName);
List<Container> containers = dockerClient.listContainers(ListContainersParam.allContainers());
for (Container container : containers) {
if (imageName.equals(container.image())) {
ContainerInfo containerInfo = dockerClient.inspectContainer(container.id());
if (containerInfo.state().running()) {
throw new IllegalStateException(String.format("container '%s' based on image '%s' is running, this test requires removing all containers created from image '%s'"));
} else {
log.debug("removing container {}", container.id());
dockerClient.removeContainer(container.id());
}
}
}
}
示例3: getImageFromRunningContainers
import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
public static Object[] getImageFromRunningContainers(){
DockerClient client = getDockerClient();
List<String> images = new ArrayList<String>();
try {
List<Container> containers = client.listContainers();
for(Container c:containers){
images.add(c.image());
}
} catch (DockerException | InterruptedException e) {
e.printStackTrace();
}
return images.toArray();
}
示例4: getRunningContainers
import com.spotify.docker.client.DockerClient; //導入方法依賴的package包/類
public static List<Container> getRunningContainers(){
DockerClient client = getDockerClient();
try {
return client.listContainers();
} catch (DockerException | InterruptedException e) {
e.printStackTrace();
}
return new ArrayList<Container>();
}