.withCmd(command); .withAttachStdout(true).withAttachStderr(true).withCmd(command).exec();
private void checkDiskSpace(DockerClient dockerClient, String id) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { dockerClient .execStartCmd(dockerClient.execCreateCmd(id).withAttachStdout(true).withCmd("df", "-P").exec().getId()) .exec(new ExecStartResultCallback(outputStream, null)) .awaitCompletion(); } catch (Exception e) { log.debug("Can't exec disk checking command", e); } DiskSpaceUsage df = parseAvailableDiskSpace(outputStream.toString()); VisibleAssertions.assertTrue( "Docker environment should have more than 2GB free disk space", df.availableMB.map(it -> it >= 2048).orElse(true) ); }
private void exposePortThroughProxy(String networkAlias, int originalPort, int mappedPort) { ExecCreateCmdResponse createCmdResponse = dockerClient .execCreateCmd(proxy.getContainerId()) .withCmd("/usr/bin/socat", "TCP-LISTEN:" + originalPort + ",fork,reuseaddr", "TCP:" + networkAlias + ":" + mappedPort) .exec(); dockerClient.execStartCmd(createCmdResponse.getId()) .exec(new ExecStartResultCallback()); }
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(); callback.addConsumer(OutputFrame.OutputType.STDOUT, stdoutConsumer); callback.addConsumer(OutputFrame.OutputType.STDERR, stderrConsumer); dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(callback).awaitCompletion(); final Container.ExecResult result = new Container.ExecResult(stdoutConsumer.toString(outputCharset), stderrConsumer.toString(outputCharset)); log.trace("{}: stdout: {}", containerName, result.getStdout());
/** * Check whether the image is available locally and pull it otherwise */ public void checkAndPullImage(DockerClient client, String image) { List<Image> images = client.listImagesCmd().withImageNameFilter(image).exec(); if (images.isEmpty()) { client.pullImageCmd(image).exec(new PullImageResultCallback()).awaitSuccess(); } }
private void checkDiskSpace(DockerClient dockerClient, String id) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { dockerClient.execStartCmd(dockerClient.execCreateCmd(id).withAttachStdout(true).withCmd("df", "-P").exec().getId()).exec(new ExecStartResultCallback(outputStream, null)).awaitCompletion(); } catch (Exception e) { log.debug("Can\'t exec disk checking command", e); } DiskSpaceUsage df = parseAvailableDiskSpace(outputStream.toString()); VisibleAssertions.assertTrue("Docker environment should have more than 2GB free disk space", df.availableMB.map(it -> it >= 2048).orElse(true)); }
public void exec(String id, String... cmd){ ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(id) .withAttachStdout(true) .withCmd(cmd).exec(); }
break; case EXEC_CREATE: result = executeExecCreateRequest(client, message).exec(); break; default:
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(); }
@Test public void network_should_reach_pingpong2_by_alias_pong() throws UnsupportedEncodingException, InterruptedException { ExecCreateCmdResponse exec = dockerClient.execCreateCmd("pingpong").withCmd("curl", "http://pong:8080/").withAttachStdout(true).exec(); ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); dockerClient.execStartCmd(exec.getId()).exec(new ExecStartResultCallback(stdOut, null)).awaitCompletion(2, TimeUnit.SECONDS); assertThat(stdOut.toString("UTF-8")).isEqualToIgnoringWhitespace(EXPECTED_RESPONSE); }
private String execCreate(String containerId, String... command) { return this.client.execCreateCmd(containerId) .withAttachStdout(true).withAttachStderr(true) .withAttachStdin(true).withTty(false) .withCmd(command).exec().getId(); } }
@Test public void network_should_reach_pingpong_by_alias_foo() throws UnsupportedEncodingException, InterruptedException { ExecCreateCmdResponse exec = dockerClient.execCreateCmd("pingpong2").withCmd("curl", "http://foo:8080/").withAttachStdout(true).exec(); ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); dockerClient.execStartCmd(exec.getId()).exec(new ExecStartResultCallback(stdOut, null)).awaitCompletion(2, TimeUnit.SECONDS); assertThat(stdOut.toString("UTF-8")).isEqualToIgnoringWhitespace(EXPECTED_RESPONSE); } }
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(); }
@Test public void network_should_reach_pingpong_by_alias_ping() throws UnsupportedEncodingException, InterruptedException { ExecCreateCmdResponse exec = dockerClient.execCreateCmd("pingpong2").withCmd("curl", "http://ping:8080/").withAttachStdout(true).exec(); ByteArrayOutputStream stdOut = new ByteArrayOutputStream(); dockerClient.execStartCmd(exec.getId()).exec(new ExecStartResultCallback(stdOut, null)).awaitCompletion(2, TimeUnit.SECONDS); assertThat(stdOut.toString("UTF-8")).isEqualToIgnoringWhitespace(EXPECTED_RESPONSE); }
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); } }
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(); }
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 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(); }
try(final DockerClient client = api.getClient()) { final ExecCreateCmd cmd = client.execCreateCmd(containerId) .withAttachStdin(true) .withAttachStdout(true) .withAttachStderr(true) .withTty(false) .withCmd("java", "-jar", remoteFs + '/' + remoting.getName(), "-noReconnect", "-noKeepAlive", "-slaveLog", remoteFs + "/agent.log"); if (StringUtils.isNotBlank(user)) { cmd.withUser(user); final ExecCreateCmdResponse exec = cmd.exec(); execId = exec.getId();