@Test(groups = "ignoreInCircleCi") public void testStopContainer() throws DockerException { final RemoteApiVersion apiVersion = getVersion(dockerClient); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("sleep", "9999").exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); dockerClient.startContainerCmd(container.getId()).exec(); LOG.info("Stopping container: {}", container.getId()); dockerClient.stopContainerCmd(container.getId()).withTimeout(2).exec(); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().getRunning(), is(equalTo(false))); final Integer exitCode = inspectContainerResponse.getState().getExitCode(); if (apiVersion.equals(VERSION_1_22)) { assertThat(exitCode, is(0)); } else { assertThat(exitCode, not(0)); } }
private String lookupImageIdFromContainer(String containerId) { try { InspectContainerResponse containerInspectResponse = docker.inspectContainerCmd(containerId).exec(); return containerInspectResponse.getImageId(); } catch (DockerException e) { logger.error("Unable to inspect container " + containerId, e); throw new OrchestrationException(e); } }
public Map<String, String> getIPAddresses() { Map<String, String> idToIpAddressMap = new HashMap<>(); for (Id id : ids()) { Conf conf = repo.conf(id); if (inclusive(id) && conf.isExposeContainerIp()) { String containerName = repo.containerName(id); InspectContainerResponse containerInspectResponse = docker.inspectContainerCmd(containerName).exec(); idToIpAddressMap.put( id.toString(), containerInspectResponse.getNetworkSettings().getIpAddress()); } } return idToIpAddressMap; }
@Test() public void inspectContainer() throws DockerException { String containerName = "generated_" + new SecureRandom().nextInt(); CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("top").withName(containerName).exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(container.getId()).exec(); assertEquals(containerInfo.getId(), container.getId()); }
@Test public void inspectContainerRestartCount() throws DockerException { CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("env").exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertThat(inspectContainerResponse.getRestartCount(), equalTo(0)); }
@Test public void inspectContainerNetworkSettings() throws DockerException { CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("env").exec(); LOG.info("Created container {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); assertFalse(inspectContainerResponse.getNetworkSettings().getHairpinMode()); }
@Test public void testWaitContainer() throws DockerException { CreateContainerResponse container = dockerClient.createContainerCmd("busybox").withCmd("true").exec(); LOG.info("Created container: {}", container.toString()); assertThat(container.getId(), not(isEmptyString())); dockerClient.startContainerCmd(container.getId()).exec(); int exitCode = dockerClient.waitContainerCmd(container.getId()).exec(); LOG.info("Container exit code: {}", exitCode); assertThat(exitCode, equalTo(0)); InspectContainerResponse inspectContainerResponse = dockerClient.inspectContainerCmd(container.getId()).exec(); LOG.info("Container Inspect: {}", inspectContainerResponse.toString()); assertThat(inspectContainerResponse.getState().isRunning(), is(equalTo(false))); assertThat(inspectContainerResponse.getState().getExitCode(), is(equalTo(exitCode))); }