Source:
private Process startWithDocker(Path projectPath, TaskRequest request, ProcessBuilder pb) { Config dockerConfig = request.getConfig().getNestedOrGetEmpty("docker"); String baseImageName = dockerConfig.get("image", String.class); String imageName; if (dockerConfig.has("build")) { List<String> buildCommands = dockerConfig.getList("build", String.class); imageName = uniqueImageName(request, baseImageName, buildCommands); buildImage(imageName, projectPath, baseImageName, buildCommands); } else { imageName = baseImageName; if (dockerConfig.has("pull-always")) { pullImage(imageName); } } ImmutableList.Builder<String> command = ImmutableList.builder(); command.add("docker").add("run"); try { command.add("-i"); command.add("--rm"); command.add("-v").add(String.format(ENGLISH, "%s:%s:rw", projectPath, projectPath)); Path workdir = (pb.directory() == null) ? Paths.get("") : pb.directory().toPath(); command.add("-w").add(workdir.normalize().toAbsolutePath().toString()); logger.debug("Running in docker: {}", command.build().stream().collect(Collectors.joining(" ")), imageName); for (Map.Entry<String, String> pair : pb.environment().entrySet()) { command.add("-e").add(pair.getKey() + "=" + pair.getValue()); } command.add(imageName); command.addAll(pb.command()); ProcessBuilder docker = new ProcessBuilder(command.build()); docker.redirectError(pb.redirectError()); docker.redirectErrorStream(pb.redirectErrorStream()); docker.redirectInput(pb.redirectInput()); docker.redirectOutput(pb.redirectOutput()); docker.directory(projectPath.toFile()); return docker.start(); } catch (IOException ex) { throw Throwables.propagate(ex); } }

Target:
private Process startWithDocker(Path projectPath, TaskRequest request, ProcessBuilder pb) { Config dockerConfig = request.getConfig().getNestedOrGetEmpty("docker"); String baseImageName = dockerConfig.get("image", String.class); String imageName; if (dockerConfig.has("build")) { List<String> buildCommands = dockerConfig.getList("build", String.class); imageName = uniqueImageName(request, baseImageName, buildCommands); buildImage(imageName, projectPath, baseImageName, buildCommands); } else { imageName = baseImageName; if (dockerConfig.get("pull-always", Boolean.class, false)) { pullImage(imageName); } } ImmutableList.Builder<String> command = ImmutableList.builder(); command.add("docker").add("run"); try { command.add("-i"); command.add("--rm"); command.add("-v").add(String.format(ENGLISH, "%s:%s:rw", projectPath, projectPath)); Path workdir = (pb.directory() == null) ? Paths.get("") : pb.directory().toPath(); command.add("-w").add(workdir.normalize().toAbsolutePath().toString()); logger.debug("Running in docker: {}", command.build().stream().collect(Collectors.joining(" ")), imageName); for (Map.Entry<String, String> pair : pb.environment().entrySet()) { command.add("-e").add(pair.getKey() + "=" + pair.getValue()); } command.add(imageName); command.addAll(pb.command()); ProcessBuilder docker = new ProcessBuilder(command.build()); docker.redirectError(pb.redirectError()); docker.redirectErrorStream(pb.redirectErrorStream()); docker.redirectInput(pb.redirectInput()); docker.redirectOutput(pb.redirectOutput()); docker.directory(projectPath.toFile()); return docker.start(); } catch (IOException ex) { throw Throwables.propagate(ex); } }