use of com.github.dockerjava.api.command.CreateContainerResponse in project tutorials by eugenp.
the class ContainerLiveTest method givenContainer_whenCommittingContainer_thenMustReturnImageId.
@Test
public void givenContainer_whenCommittingContainer_thenMustReturnImageId() {
// given
CreateContainerResponse container = dockerClient.createContainerCmd("alpine:3.6").withCmd("sleep", "10000").exec();
// when
String imageId = dockerClient.commitCmd(container.getId()).withEnv("SNAPSHOT_YEAR=2018").withMessage("add git support").withCmd("sleep", "10000").withRepository("alpine").withTag("3.6.v2").exec();
// then
assertThat(imageId, is(not(null)));
}
use of com.github.dockerjava.api.command.CreateContainerResponse in project hub-docker-inspector by blackducksoftware.
the class DockerClientManager method ensureContainerRunning.
private String ensureContainerRunning(final DockerClient dockerClient, final String imageId, final String extractorContainerName, final String hubPassword, final String hubApiToken) {
String oldContainerId;
final List<Container> containers = dockerClient.listContainersCmd().withShowAll(true).exec();
final Container extractorContainer = getRunningContainer(containers, extractorContainerName);
if (extractorContainer != null) {
logger.debug(String.format("Extractor container status: %s", extractorContainer.getStatus()));
oldContainerId = extractorContainer.getId();
if (extractorContainer.getStatus().startsWith("Up")) {
logger.debug("The extractor container is running; stopping it");
dockerClient.stopContainerCmd(oldContainerId).exec();
}
logger.debug("The extractor container exists; removing it");
dockerClient.removeContainerCmd(oldContainerId).exec();
}
logger.debug(String.format("Creating container %s from image %s", extractorContainerName, imageId));
final CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(imageId).withStdinOpen(true).withTty(true).withName(extractorContainerName).withCmd("/bin/bash");
final List<String> envAssignments = new ArrayList<>();
envAssignments.add(String.format("BD_HUB_PASSWORD=%s", hubPassword));
envAssignments.add(String.format("BD_HUB_TOKEN=%s", hubApiToken));
if ((StringUtils.isBlank(config.getHubProxyHost())) && (!StringUtils.isBlank(config.getScanCliOptsEnvVar()))) {
envAssignments.add(String.format("SCAN_CLI_OPTS=%s", config.getScanCliOptsEnvVar()));
} else {
}
createContainerCmd.withEnv(envAssignments);
final CreateContainerResponse containerResponse = createContainerCmd.exec();
final String containerId = containerResponse.getId();
dockerClient.startContainerCmd(containerId).exec();
logger.info(String.format("Started container %s from image %s", containerId, imageId));
return containerId;
}
Aggregations