log.info(MessageFormat.format("Image will be built as {0}", name)); log.info(""); // Spacing around build progress dockerClient.build(contextDirectory, name, progressHandler, buildParametersArray); } else { log.info("Image will be built without a name"); log.info(""); // Spacing around build progress dockerClient.build(contextDirectory, progressHandler, buildParametersArray);
@Before public void setup() throws Exception { try (final DockerClient docker = getNewDockerClient()) { // Build an image with an ENTRYPOINT and CMD prespecified final String dockerDirectory = Resources.getResource("syslog-test-image").getPath(); docker.build(Paths.get(dockerDirectory), testImage); // Figure out the host IP from the container's point of view (needed for syslog) final ContainerConfig config = ContainerConfig.builder() .image(BUSYBOX) .cmd(asList("ip", "route", "show")) .build(); final ContainerCreation creation = docker.createContainer(config); final String containerId = creation.id(); docker.startContainer(containerId); // Wait for the container to exit. // If we don't wait, docker.logs() might return an epmty string because the container // cmd hasn't run yet. docker.waitContainer(containerId); final String log; try (LogStream logs = docker.logs(containerId, stdout(), stderr())) { log = logs.readFully(); } final Matcher m = DEFAULT_GATEWAY_PATTERN.matcher(log); if (m.find()) { syslogHost = m.group("gateway"); } else { fail("couldn't determine the host address from '" + log + "'"); } } }
DockerInstanceBuilder(Path dirToCustomDockerFile, String imageName) { this.imageName = imageName; this.imageStrategy = (client) -> client.build(dirToCustomDockerFile, imageName); }
public Result build(final DockerClient dockerClient, String pathUri, ReadOnlyImage readOnlyImage) { String repository = readOnlyImage.getRepository(); String imageId; String errMsg = "build image failed."; try { imageId = dockerClient.build(Paths.get(pathUri), repository); return imageId == null ? new Result().fail(errMsg) : new Result().success(imageId); } catch (DockerException e) { errMsg = e.getMessage(); logger.error("build image exception.", e); } catch (InterruptedException e) { errMsg = e.getMessage(); logger.error("build image exception.", e); } catch (IOException e) { errMsg = e.getMessage(); logger.error("build image exception.", e); } catch (Exception e) { errMsg = e.getMessage(); logger.error("build image exception.", e); } return new Result().fail(errMsg); }