.withAttachStdout(true).withAttachStderr(true).withCmd(command).exec();
.withAttachStdin(true) .withAttachStdout(true) .withAttachStderr(true) .withTty(false) .withCmd("java", "-jar", remoteFs + '/' + remoting.getName(), "-noReconnect", "-noKeepAlive", "-slaveLog", remoteFs + "/agent.log");
public static ExecCmdResult execCmd(DockerClient dockerClient, String containerId, String[] command) { ExecCreateCmdResponse cmd = dockerClient.execCreateCmd(containerId) .withAttachStdout(true) .withAttachStderr(true) .withCmd(command) .exec(); String cmdStdout; String cmdStderr; try (ByteArrayOutputStream stdout = new ByteArrayOutputStream(); ByteArrayOutputStream stderr = new ByteArrayOutputStream(); ExecStartResultCallback cmdCallback = new ExecStartResultCallback(stdout, stderr)) { dockerClient.execStartCmd(cmd.getId()).exec(cmdCallback).awaitCompletion(); cmdStdout = stdout.toString(StandardCharsets.UTF_8.name()); cmdStderr = stderr.toString(StandardCharsets.UTF_8.name()); } catch (Exception e) { String format = String.format("Exception was thrown when executing: %s, for container: %s ", Arrays.toString(command), containerId); throw new IllegalStateException(format, e); } int exitCode = dockerClient.inspectExecCmd(cmd.getId()).exec().getExitCode(); String output = cmdStdout.isEmpty() ? cmdStderr : cmdStdout; return new ExecCmdResult(exitCode, 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; }
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; }
private String execCreate(String containerId, String... commands) { ExecCreateCmdResponse execCreateCmdResponse = this.dockerClient.execCreateCmd(containerId) .withAttachStdout(true).withAttachStdin(true).withAttachStderr(true).withTty(false).withCmd(commands) .exec(); return execCreateCmdResponse.getId(); }
private ExecCreateCmdResponse execCreateCmd(ContainerName containerName, String user, String... command) { try { return dockerClient.execCreateCmd(containerName.asString()) .withCmd(command) .withAttachStdout(true) .withAttachStderr(true) .withUser(user) .exec(); } catch (NotFoundException e) { throw new ContainerNotFoundException(containerName); } }
private String execCreate(String containerId, String... commands) { ExecCreateCmdResponse execCreateCmdResponse = this.dockerClient.execCreateCmd(containerId) .withAttachStdout(true).withAttachStdin(true).withAttachStderr(true).withTty(false).withCmd(commands) .exec(); return execCreateCmdResponse.getId(); }
private String execCreate(String containerId, String... command) { return this.client.execCreateCmd(containerId) .withAttachStdout(true).withAttachStderr(true) .withAttachStdin(true).withTty(false) .withCmd(command).exec().getId(); } }
client.execCreateCmd(containerId) .withAttachStdout(true) .withAttachStderr(true) .withTty(true) .withCmd("sh", "-c", "" +
.withCmd(command) .withAttachStdout(true) .withAttachStderr(true) .exec() .getId();
.withCmd(command) .withAttachStdout(true) .withAttachStderr(true) .exec() .getId();
dockerClient.execCreateCmd(containerId).withCmd(command); log.debug("{}: Running \"exec\" command: {}", containerName, String.join(" ", command)); final ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId).withAttachStdout(true).withAttachStderr(true).withCmd(command).exec(); final ToStringConsumer stdoutConsumer = new ToStringConsumer(); final ToStringConsumer stderrConsumer = new ToStringConsumer();
public String call() throws Exception { DockerClient client = DockerCommand.getClient(descriptor, cfgData.dockerUrlRes, cfgData.dockerVersionRes, cfgData.dockerCertPathRes, null); final ExecCreateCmdResponse response; if (withAttachStdoutAndStderr) { response = client.execCreateCmd(id).withCmd(cmd).withAttachStderr(true).withAttachStdout(true).exec(); } else { response = client.execCreateCmd(id).withCmd(cmd).exec(); } return response.getId(); }
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"); } }
execCreateCmd.withAttachStderr(attachStdErr);