private ContainerInfo getContainerInfo(final String existingContainerId) throws DockerException, InterruptedException { if (existingContainerId == null) { return null; } log.info("inspecting container: {}: {}", config, existingContainerId); try { return docker.inspectContainer(existingContainerId); } catch (ContainerNotFoundException e) { return null; } }
protected String getBridgeAddress(String containerId) throws DockerException, InterruptedException { return dockerClient.inspectContainer(containerId).networkSettings().gateway(); } }
@Override public Object call() throws Exception { final ContainerInfo info = docker.inspectContainer(containerId); return info.state().running() ? true : null; } });
private String containerError() throws InterruptedException { if (containerId == null) { return null; } final ContainerInfo containerInfo; try { containerInfo = docker.inspectContainer(containerId); } catch (ContainerNotFoundException e) { return null; } catch (DockerException e) { log.error("failed to query container {}", containerId, e); return null; } return containerInfo.state().error(); } }
private boolean containerRunning() throws InterruptedException { if (containerId == null) { return false; } final ContainerInfo containerInfo; try { containerInfo = docker.inspectContainer(containerId); } catch (ContainerNotFoundException e) { return false; } catch (DockerException e) { log.error("failed to query container {}", containerId, e); // Assume the container is running as we don't know for sure either way. return true; } return containerInfo.state().running(); }
private synchronized List<String> getContainerExtraHosts(String zaleniumContainerName) { if (zaleniumExtraHosts != null) { return zaleniumExtraHosts; } String containerId = getContainerId(zaleniumContainerName); ContainerInfo containerInfo; try { containerInfo = dockerClient.inspectContainer(containerId); zaleniumExtraHosts = containerInfo.hostConfig().extraHosts(); } catch (DockerException | InterruptedException | NullPointerException e) { logger.debug(nodeId + " Error while getting Zalenium extra hosts.", e); ga.trackException(e); } return Optional.ofNullable(zaleniumExtraHosts).orElse(new ArrayList<>()); }
private void loadMountedFolders(String zaleniumContainerName) { if (!this.mntFoldersAndHttpEnvVarsChecked.get()) { String containerId = getContainerId(zaleniumContainerName); if (containerId == null) { return; } ContainerInfo containerInfo = null; try { containerInfo = dockerClient.inspectContainer(containerId); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Error while getting mounted folders and env vars.", e); ga.trackException(e); } loadMountedFolders(containerInfo); } }
private synchronized String getZaleniumNetwork(String zaleniumContainerName) { if (zaleniumNetwork != null) { return zaleniumNetwork; } String zaleniumContainerId = getContainerId(zaleniumContainerName); if (zaleniumContainerId == null) { logger.warn(String.format("Couldn't find selenium container with name or containing: %s, check that the env " + "variable ZALENIUM_CONTAINER_NAME has an appropriate value", zaleniumContainerName)); } try { ContainerInfo containerInfo = dockerClient.inspectContainer(zaleniumContainerId); ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks(); for (Map.Entry<String, AttachedNetwork> networkEntry : networks.entrySet()) { if (!DEFAULT_DOCKER_NETWORK_NAME.equalsIgnoreCase(networkEntry.getKey())) { zaleniumNetwork = networkEntry.getKey(); return zaleniumNetwork; } } } catch (DockerException | InterruptedException | NullPointerException e) { logger.debug(nodeId + " Error while getting Zalenium network. Falling back to default.", e); ga.trackException(e); } zaleniumNetwork = DEFAULT_DOCKER_NETWORK_MODE; return zaleniumNetwork; }
private void loadIsZaleniumPrivileged(String zaleniumContainerName) { if (!this.isZaleniumPrivilegedChecked.getAndSet(true)) { String containerId = getContainerId(zaleniumContainerName); if (containerId == null) { return; } ContainerInfo containerInfo; try { containerInfo = dockerClient.inspectContainer(containerId); isZaleniumPrivileged = containerInfo.hostConfig().privileged(); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Error while getting value to check if Zalenium is running in privileged mode.", e); ga.trackException(e); } } }
private void loadStorageOpts(String zaleniumContainerName) { if (!this.storageOptsLoaded.getAndSet(true)) { String containerId = getContainerId(zaleniumContainerName); if (containerId == null) { return; } ContainerInfo containerInfo; try { containerInfo = dockerClient.inspectContainer(containerId); storageOpt = containerInfo.hostConfig().storageOpt(); } catch (DockerException | InterruptedException e) { logger.warn(nodeId + " Error while getting value to use passed storageOpts.", e); ga.trackException(e); } } }
@Override public boolean isTerminated(ContainerCreationStatus container) { try { final ContainerInfo info = dockerClient.inspectContainer(container.getContainerId()); if (info.state().status().equalsIgnoreCase("exited") || info.state().status().equalsIgnoreCase("dead")) { logger.debug("Container {} exited with status {} - it is terminated.", container, info.state().status()); return true; } return false; } catch (ContainerNotFoundException e) { logger.debug("Container {} not found - it is terminated.", container); return true; } catch (DockerException | InterruptedException e) { logger.warn("Failed to fetch container status [" + container + "].", e); return false; } } }
@Override public String getContainerIp(String containerName) { String containerId = this.getContainerId(containerName); if (containerId == null) { return null; } try { ContainerInfo containerInfo = dockerClient.inspectContainer(containerId); if (containerInfo.networkSettings().ipAddress().trim().isEmpty()) { ImmutableMap<String, AttachedNetwork> networks = containerInfo.networkSettings().networks(); return networks.entrySet().stream().findFirst().get().getValue().ipAddress(); } return containerInfo.networkSettings().ipAddress(); } catch (DockerException | InterruptedException e) { logger.debug(nodeId + " Error while getting the container IP.", e); ga.trackException(e); } return null; }
return dockerClient.inspectContainer(container.id()) .config() .exposedPorts()
@Override public ContainerInfo call() throws Exception { return dockerClient.inspectContainer(containerName); } };
docker.inspectContainer(taskStatus.getContainerId()).hostConfig();
@Test public void test() throws Exception { final CreateJobResponse created = client.createJob(job).get(); assertEquals(CreateJobResponse.Status.OK, created.getStatus()); final JobId jobId = job.getId(); // Wait for agent to come up awaitHostRegistered(client, testHost(), LONG_WAIT_SECONDS, SECONDS); awaitHostStatus(client, testHost(), UP, LONG_WAIT_SECONDS, SECONDS); // Deploy the job on the agent final Deployment deployment = Deployment.of(jobId, START); final JobDeployResponse deployed = client.deploy(deployment, testHost()).get(); assertEquals(JobDeployResponse.Status.OK, deployed.getStatus()); // Wait for the job to run final TaskStatus taskStatus = awaitJobState( client, testHost(), jobId, RUNNING, LONG_WAIT_SECONDS, SECONDS); try (final DockerClient docker = getNewDockerClient()) { final HostConfig hostConfig = docker.inspectContainer(taskStatus.getContainerId()).hostConfig(); assertEquals(NETWORK_MODE, hostConfig.networkMode()); } } }
docker.startContainer(syslogContainerId); final ContainerInfo containerInfo = docker.inspectContainer(syslogContainerId); assertThat(containerInfo.state().running(), equalTo(true)); final String logType = docker.inspectContainer(taskStatus.getContainerId()) .hostConfig().logConfig().logType(); assertEquals("syslog", logType);
LONG_WAIT_SECONDS, SECONDS); assertJobEquals(job, firstTaskStatus.getJob()); assertNotNull(dockerClient.inspectContainer(firstTaskStatus.getContainerId())); dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running()); dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running()); dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running()); assertFalse(dockerClient.inspectContainer(firstRestartedContainerId).state().running()); assertTrue(dockerClient.inspectContainer(secondRestartedContainerId).state().running());
assertJobEquals(job, firstTaskStatus.getJob()); assertEquals(1, listContainers(dockerClient, testTag).size()); assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running()); assertTrue(dockerClient.inspectContainer(firstTaskStatus.getContainerId()).state().running()); assertTrue(dockerClient.inspectContainer(secondTaskStatus.getContainerId()).state().running()); assertTrue(dockerClient.inspectContainer(thirdTaskStatus.getContainerId()).state().running());
public String containerIp(String buildContainerId) { try { return dockerClient.inspectContainer(buildContainerId).networkSettings().ipAddress(); } catch (DockerException | InterruptedException e) { logger.error("", e); } return null; }