@Override public Void call() throws Exception { log.trace("{} attaching to logs", containerShortId); LogStream logs = dockerClient.logs(containerId, LogsParam.stdout(), LogsParam.stderr(), LogsParam.follow()); try { logs.attach(logSplitter.getStdoutOutput(), logSplitter.getStderrOutput()); } finally { IOUtils.closeQuietly(logs, logSplitter); log.trace("{} dettached from logs", containerShortId); } return null; } });
public void start(DockerClient dockerClient) throws DockerException, InterruptedException, IOException { dockerClient.startContainer(container.id()); Thread thread = new Thread(() -> { try { dockerClient.attachContainer(container.id(), DockerClient.AttachParameter.LOGS, DockerClient.AttachParameter.STDOUT, DockerClient.AttachParameter.STDERR, DockerClient.AttachParameter.STREAM) .attach(System.out, System.err); } catch (Exception e) { e.printStackTrace(); } }); thread.setDaemon(true); thread.start(); }