Refine search
protected InspectContainerResponse.ContainerState getCurrentState(DockerClient dockerClient, String containerId) { return dockerClient.inspectContainerCmd(containerId).exec().getState(); }
@Override protected InspectContainerResponse execute(InspectContainerCmd command) { WebTarget webResource = getBaseResource().path("/containers/{id}/json") .resolveTemplate("id", command.getContainerId()); webResource = booleanQueryParam(webResource, "size", command.getSize()); LOGGER.debug("GET: {}", webResource); return webResource.request().accept(MediaType.APPLICATION_JSON).get(InspectContainerResponse.class); }
private void logNetworks(String containerId) { Map<String, ContainerNetwork> networks = getClient().inspectContainerCmd(containerId).exec().getNetworkSettings().getNetworks(); int networksSize = networks.size(); log.debug("There are {} network(s) in the container {}", networksSize, containerId); if (networksSize == 0) { return; } int i = 0; for (Entry<String, ContainerNetwork> network : networks.entrySet()) { log.debug("{}) {} -> {}", ++i, network.getKey(), network.getValue()); } }
CreateContainerCmd createCommand = dockerClient.createContainerCmd(dockerImageName); applyConfiguration(createCommand); dockerClient.startContainerCmd(containerId).exec(); containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); containerName = containerInfo.getName(); containerIsStarting(containerInfo);
default InspectContainerResponse getCurrentContainerInfo() { return DockerClientFactory.instance().client().inspectContainerCmd(getContainerId()).exec(); }
.createContainerCmd(imageName) .withWorkingDir(workingDir) .withCmd(command) if (fr.getBytes() != null) stdoutConsumer.accept(fr.getUtf8String().trim()); }); dockerClient.startContainerCmd(exec.getId()).exec(); dockerClient.logContainerCmd(exec.getId()).withFollowStream(true).withStdErr(true).withStdOut(true).exec(callback); while (dockerClient.inspectContainerCmd(exec.getId()).exec().getState().getRunning()) { try { Thread.sleep(300); return dockerClient.inspectContainerCmd(exec.getId()).exec().getState().getExitCode(); } finally { dockerClient.removeContainerCmd(exec.getId()).exec();
private void stopContainer(String containerId, String imageName) { boolean running; try { InspectContainerResponse containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); running = containerInfo.getState().getRunning(); } catch (NotFoundException e) { LOGGER.trace("Was going to stop container but it apparently no longer exists: {}", containerId); try { LOGGER.trace("Stopping container: {}", containerId); dockerClient.killContainerCmd(containerId).exec(); LOGGER.trace("Stopped container: {}", imageName); } catch (DockerException e) { dockerClient.inspectContainerCmd(containerId).exec(); } catch (NotFoundException e) { LOGGER.trace("Was going to remove container but it apparently no longer exists: {}", containerId);
@Test @DisplayName("start a container without ports") public void shouldStartContainer() { String containerId = defaultDockerClient.startContainer(WANTED_IMAGE, emptyMap()); assertThat(dockerClient.listContainersCmd().exec()).hasSize(existingContainers.size() + 1); InspectContainerResponse startedContainer = dockerClient.inspectContainerCmd(containerId).exec(); assertThat(startedContainer.getConfig().getImage()).isEqualTo(WANTED_IMAGE); }
public static Binding binding(DockerClientExecutor executor, String cubeId) { InspectContainerResponse inspectResponse = executor.getDockerClient().inspectContainerCmd(cubeId).exec(); String dockerIp = getDockerServerIp(executor); String inernalIp = null; NetworkSettings networkSettings = inspectResponse.getNetworkSettings(); if (networkSettings != null) { inernalIp = networkSettings.getIpAddress(); } Binding binding = new Binding(dockerIp, inernalIp); HostConfig hostConfig = inspectResponse.getHostConfig(); if (hostConfig.getPortBindings() != null) { for (Entry<ExposedPort, com.github.dockerjava.api.model.Ports.Binding[]> bind : hostConfig.getPortBindings() .getBindings().entrySet()) { com.github.dockerjava.api.model.Ports.Binding[] allBindings = bind.getValue(); for (com.github.dockerjava.api.model.Ports.Binding bindings : allBindings) { binding.addPortBinding(bind.getKey().getPort(), Integer.parseInt(bindings.getHostPortSpec())); } } } else { ContainerConfig connectionConfig = inspectResponse.getConfig(); final ExposedPort[] exposedPorts = connectionConfig.getExposedPorts(); if (exposedPorts != null) { for (ExposedPort port : exposedPorts) { binding.addPortBinding(port.getPort(), -1); } } } return binding; }
StartContainerCmd startContainerCmd = connection.getDockerClient().startContainerCmd(containerId); startContainerCmd.exec(); if (StringUtils.isNotBlank(connection.getDockerNetworkId())) { log.info("Connecting container {} to network {}", containerId, connection.getDockerNetworkId(), context); connection.getDockerClient().connectToNetworkCmd().withContainerId(containerId).withNetworkId(connection.getDockerNetworkId()).exec(); log.info("Connected container {} to network {}", containerId, connection.getDockerNetworkId(), context); for (Network network : networks) { log.info("Connecting container {} to network {}", containerId, network.getId(), context); connection.getDockerClient().connectToNetworkCmd().withContainerId(containerId).withNetworkId(network.getNetworkId()).exec(); log.info("Connected container {} to network {}", containerId, network.getId(), context); InspectContainerResponse response = connection.getDockerClient().inspectContainerCmd(containerId).exec(); if (response.getNetworkSettings().getNetworks() == null || response.getNetworkSettings().getNetworks().isEmpty()) { ipAddress = response.getNetworkSettings().getIpAddress(); } else {
protected void createContainer(DockerClient dockerClient) throws InterruptedException { pullImage(dockerClient); CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(properties.getDockerImage()) // NOSONAR .withLabels(getAllLabels()) .withEnv(getEnvs()) .withHostConfig(buildHostConfig()); adjustCreateCommand(createContainerCmd); String containerId = createContainerCmd.exec().getId(); dockerClient.startContainerCmd(containerId).exec(); containerInfo = dockerClient.inspectContainerCmd(containerId).exec(); }
@Test public void sharedMemorySetTest() { try (GenericContainer containerWithSharedMemory = new GenericContainer("busybox:1.29") .withSharedMemorySize(1024L * FileUtils.ONE_MB)) { containerWithSharedMemory.start(); HostConfig hostConfig = containerWithSharedMemory.getDockerClient().inspectContainerCmd(containerWithSharedMemory.getContainerId()) .exec().getHostConfig(); assertEquals("Shared memory not set on container", hostConfig.getShmSize(), 1024 * FileUtils.ONE_MB); } } }
public void updateStartedForTest() { containersStartedByExtensionPerTest = getContainers().stream() .filter(c -> !containersStartedByExtension.contains(c)) .collect(Collectors.toList()); containersInspectPerTest = containersStartedByExtensionPerTest.stream() .map(c -> dockerClient.inspectContainerCmd(c.getId()).exec()) .collect(Collectors.toList()); logsPerTest = containersStartedByExtensionPerTest.stream() .map(c -> dockerClient.logContainerCmd(c.getId()) .withStdOut(true) .withStdErr(true) .exec(new LogCallback())) .collect(Collectors.toList()); }
@Test public void container_should_be_attached_to_back_network() { final InspectContainerResponse pingpong = dockerClient.inspectContainerCmd("pingpong").exec(); final Network front = dockerClient.inspectNetworkCmd().withNetworkId("back").exec(); assertThat(front.getContainers()).containsOnlyKeys(pingpong.getId()); }
@Test public void container_should_have_static_ip_for_app_net_network() throws InterruptedException, IOException { final InspectContainerResponse pingpong = dockerClient.inspectContainerCmd("pingpong").exec(); ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(pingpong.getId()) .withAttachStdout(true).withAttachStdin(true).withAttachStderr(true).withTty(false).withCmd("ifconfig") .exec(); try (OutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = new ByteArrayOutputStream()) { dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false) .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion(); assertThat(outputStream.toString()).contains("inet addr:172.16.238.10", "inet6 addr: fe80::42:acff:fe10:ee0a/64"); } }
InspectContainerResponse icr = null; try { icr = this.dockerClient.inspectContainerCmd(id).exec(); } catch (NotFoundException e) { return; if (!icr.getState().getStatus().equals("paused")) { return; if (!icr.getState().getRunning()) { return; this.dockerClient.unpauseContainerCmd(id).exec(); Ports.Binding binding = icr.getNetworkSettings().getPorts().getBindings().get(exposedPort)[0]; URI publicUri = UriUtils.buildUri(UriUtils.HTTP_SCHEME, binding.getHostIp(), Integer.valueOf(binding.getHostPortSpec()), null, null, null);
public static String getContainerHostname(GenericContainer container) { InspectContainerResponse containerInfo = container.getContainerInfo(); if (containerInfo == null) { containerInfo = container.getDockerClient().inspectContainerCmd(container.getContainerId()).exec(); } return containerInfo.getConfig().getHostName(); }
public String call() throws Exception { DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null); CreateContainerCmd cfgCmd = client.createContainerCmd(imageRes); if (commandRes != null) { cfgCmd.withCmd(commandRes); InspectContainerResponse inspectResp = client.inspectContainerCmd(resp.getId()).exec();
public String call() throws Exception { DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null); client.startContainerCmd(id).exec(); InspectContainerResponse inspectResp = client.inspectContainerCmd(id).exec(); ObjectMapper mapper = new ObjectMapper(); String serialized = mapper.writeValueAsString(inspectResp); return serialized; }
private void logMounts(String containerId) { InspectContainerResponse exec = getClient().inspectContainerCmd(containerId).exec(); List<Mount> mounts = exec.getMounts(); log.debug("There are {} mount(s) in the container {}:", mounts.size(), containerId); for (int i = 0; i < mounts.size(); i++) { Mount mount = mounts.get(i); log.debug("{}) {} -> {} ({})", i + 1, mount.getSource(), mount.getDestination(), mount.getMode()); } }