public void execStartDetached(String containerId, String... commands) { this.readWriteLock.readLock().lock(); try { String id = execCreate(containerId, commands); this.dockerClient.execStartCmd(id).withDetach(true).exec(new ExecStartResultCallback()); } finally { this.readWriteLock.readLock().unlock(); } }
public void execStartDetached(String containerId, String... commands) { this.readWriteLock.readLock().lock(); try { String id = execCreate(containerId, commands); this.dockerClient.execStartCmd(id).withDetach(true).exec(new ExecStartResultCallback()); } finally { this.readWriteLock.readLock().unlock(); } }
private CubeOutput getOutputOfCommand(String containerId, String[] command) { String execResponseId = execCreate(containerId, command); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = new ByteArrayOutputStream(); try { this.client.execStartCmd(execResponseId).withDetach(false) .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion(); } catch (InterruptedException e) { return new CubeOutput("", ""); } return new CubeOutput(outputStream.toString().trim(), errorStream.toString().trim()); }
private CubeOutput execStartOutput(String id) { OutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = new ByteArrayOutputStream(); try { dockerClient.execStartCmd(id).withDetach(false) .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion(); } catch (InterruptedException e) { return new CubeOutput("", ""); } return new CubeOutput(outputStream.toString(), errorStream.toString()); }
private CubeOutput execStartOutput(String id) { OutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = new ByteArrayOutputStream(); try { dockerClient.execStartCmd(id).withDetach(false) .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion(); } catch (InterruptedException e) { return new CubeOutput("", ""); } return new CubeOutput(outputStream.toString(), errorStream.toString()); }
public String execCommand(String containerId, boolean awaitCompletion, String... command) { ExecCreateCmdResponse exec = client.execCreateCmd(containerId).withCmd(command).withTty(false) .withAttachStdin(true).withAttachStdout(true).withAttachStderr(true).exec(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String output = null; try { ExecStartResultCallback resultCallback = client.execStartCmd(exec.getId()).withDetach(false) .withTty(true).exec(new ExecStartResultCallback(outputStream, System.err)); if (awaitCompletion) { resultCallback.awaitCompletion(); } output = new String(outputStream.toByteArray()); } catch (InterruptedException e) { log.warn("Exception executing command {} on container {}", Arrays.toString(command), containerId, e); } return output; }
public String execCommand(String containerId, boolean awaitCompletion, String... command) { ExecCreateCmdResponse exec = client.execCreateCmd(containerId).withCmd(command).withTty(false) .withAttachStdin(true).withAttachStdout(true).withAttachStderr(true).exec(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); String output = null; try { ExecStartResultCallback resultCallback = client.execStartCmd(exec.getId()).withDetach(false) .withTty(true).exec(new ExecStartResultCallback(outputStream, System.err)); if (awaitCompletion) { resultCallback.awaitCompletion(); } output = new String(outputStream.toByteArray()); } catch (InterruptedException e) { log.warn("Exception executing command {} on container {}", Arrays.toString(command), containerId, e); } return output; }
execStartCmd.withDetach(detach);
.withTty(true) .withExecId(execID) .withDetach(false) .exec(execStartResultCallback).awaitCompletion();
.withTty(true) .withExecId(execID) .withDetach(false) .exec(execStartResultCallback).awaitCompletion();
private String asyncRunCommand(String command, InputStream input, DockerStreamDecoder outputDecoder) { ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId) .withAttachStdin(true) .withAttachStdout(true) .withAttachStderr(true) .withCmd(command.split("\\s")) .exec(); ExecStartCmd execStartCmd = dockerClient.execStartCmd(containerId) .withTty(false) .withExecId(execCreateCmdResponse.getId()) .withDetach(false); if (input != null) { execStartCmd.withStdIn(input); } execStartCmd.exec(outputDecoder); return execCreateCmdResponse.getId(); }
@Test public void container_should_have_static_ip_for_app_net_network() throws InterruptedException, IOException { final InspectContainerResponse pingpong = dockerClient.inspectContainerCmd("pingpong").exec(); ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(pingpong.getId()) .withAttachStdout(true).withAttachStdin(true).withAttachStderr(true).withTty(false).withCmd("ifconfig") .exec(); try (OutputStream outputStream = new ByteArrayOutputStream(); OutputStream errorStream = new ByteArrayOutputStream()) { dockerClient.execStartCmd(execCreateCmdResponse.getId()).withDetach(false) .exec(new ExecStartResultCallback(outputStream, errorStream)).awaitCompletion(); assertThat(outputStream.toString()).contains("inet addr:172.16.238.10", "inet6 addr: fe80::42:acff:fe10:ee0a/64"); } }