@Test public void info() throws DockerException { // Make sure that there is at least one container for the assertion // TODO extract this into a shared method if (dockerClient.listContainersCmd().withShowAll(true).exec().size() == 0) { CreateContainerResponse container = dockerClient .createContainerCmd("busybox") .withName("docker-java-itest-info") .withCmd("touch", "/test") .exec(); LOG.info("Created container: {}", container); assertThat(container.getId(), not(isEmptyOrNullString())); dockerClient.startContainerCmd(container.getId()).exec(); } Info dockerInfo = dockerClient.infoCmd().exec(); LOG.info(dockerInfo.toString()); assertTrue(dockerInfo.toString().contains("containers")); assertTrue(dockerInfo.toString().contains("images")); assertTrue(dockerInfo.toString().contains("debug")); assertTrue(dockerInfo.getContainers() > 0); assertTrue(dockerInfo.getImages() > 0); assertTrue(dockerInfo.getNFd() > 0); assertTrue(dockerInfo.getNGoroutines() > 0); assertTrue(dockerInfo.getNCPU() > 0); }
/** @param args */ public static void main(String[] args) { DockerClient dockerClient = getDockerClient("10.10.10.6"); Info info = dockerClient.infoCmd().exec(); System.out.println("Client info: {}" + info.toString()); int imgCount = info.getImages(); System.out.println("imgCount1: {}" + dockerClient.listImagesCmd().exec().size()); // This should be an image that is not used by other repositories // already // pulled down, preferably small in size. If tag is not used pull will // download all images in that repository but tmpImgs will only // deleted 'latest' image but not images with other tags String testImage = "10.10.10.3/hello"; System.out.println("Removing image: {}" + testImage); try { dockerClient.removeImageCmd(testImage).withForce().exec(); } catch (NotFoundException e) { // just ignore if not exist } info = dockerClient.infoCmd().exec(); System.out.println("Client info: {}" + info.toString()); imgCount = info.getImages(); System.out.println("imgCount2: {}" + dockerClient.listImagesCmd().exec().size()); System.out.println("Pulling image: {}" + testImage); dockerClient .pullImageCmd(testImage) .withRepository("10.10.10.3/new11imageha12122h121221a") .withTag("first") .exec(new PullImageResultCallback()) .awaitSuccess(); info = dockerClient.infoCmd().exec(); System.out.println("Client info after pull, {}" + info.toString()); assertThat(imgCount, lessThanOrEqualTo(info.getImages())); InspectImageResponse inspectImageResponse = dockerClient.inspectImageCmd(testImage).exec(); System.out.println("Image Inspect: {}" + inspectImageResponse.toString()); assertThat(inspectImageResponse, notNullValue()); }