public void executeCommand(String containerId, String[] command, boolean waitForExecution) { final ExecCreation execCreation; try { execCreation = dockerClient.execCreate(containerId, command, DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr(), DockerClient.ExecCreateParam.attachStdin()); final LogStream output = dockerClient.execStart(execCreation.id()); logger.debug(String.format("%s %s", nodeId, Arrays.toString(command))); if (waitForExecution) { try { String commandOutput = output.readFully(); logger.debug(String.format("%s %s", nodeId, commandOutput)); } catch (Exception e) { logger.debug(nodeId + " Error while executing the output.readFully()", e); ga.trackException(e); } } } catch (DockerException | InterruptedException | NullPointerException e) { logger.debug(nodeId + " Error while executing the command", e); ga.trackException(e); } }
final ExecCreation execCreation = docker.execCreate( containerId, cmd, DockerClient.ExecCreateParam.attachStdout(),
final ExecCreation execCreation = dockerClient.execCreate( jobState.getContainerId(), makeFileCmd); final String execId = execCreation.id();
DockerClient dockerClient = DefaultDockerClient.builder() .uri( dockerURI ) .readTimeoutMillis( Long.MAX_VALUE ) // without this interactive session may disconnect .build(); // use other config options if appropriate String execId = dockerClient.execCreate(id, new String[] {"/bin/bash"}, ExecCreateParam.attachStdin(), ExecCreateParam.attachStdout(), ExecCreateParam.attachStderr(), ExecCreateParam.tty() ); LogStream ls = dockerClient.execStart( execId );
/** * Run `docker exec` on a container */ public void execCommand(String containerName, String... command) throws DockerException, InterruptedException { log.info("Executing docker command: {}", String.join(" ", command)); ExecCreation execCreation = docker.execCreate( containerName, command, DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr() ); docker.execStart(execCreation.id()); }
@Override public boolean check(final String containerId) { // Make sure we are on a docker version that supports exec health checks if (!compatibleDockerVersion(docker)) { throw new UnsupportedOperationException( "docker exec healthcheck is not supported on your docker version"); } try { final List<String> cmd = healthCheck.getCommand(); final String execId = docker.execCreate(containerId, cmd.toArray(new String[cmd.size()]), DockerClient.ExecParameter.STDOUT, DockerClient.ExecParameter.STDERR); final String output; try (LogStream stream = docker.execStart(execId)) { output = stream.readFully(); } final int exitCode = docker.execInspect(execId).exitCode(); if (exitCode != 0) { log.info("healthcheck failed with exit code {}. output {}", exitCode, output); return false; } return true; } catch (DockerException e) { return false; } catch (InterruptedException e) { Thread.currentThread().interrupt(); return false; } }
public String execCommandInContainer(String containerId, String... command) throws DockerException, InterruptedException { String[] shCommand = { "sh", "-c" }; String[] finalCommand = (String[]) ArrayUtils.addAll(shCommand, command); String commandStr = Arrays.toString(finalCommand); log.trace("Running command {} in container {}", commandStr, containerId); String execId = dockerClient.execCreate(containerId, finalCommand, DockerClient.ExecCreateParam.attachStdout(), DockerClient.ExecCreateParam.attachStderr()).id(); String output = null; try (LogStream stream = dockerClient.execStart(execId)) { output = stream.readFully(); } log.trace("Result of command {} in container {}: {}", commandStr, containerId, output); return output; }
String execId = docker.execCreate(containerId, new String[]{ "/opt/couchbase/bin/couchbase-cli"
final String execId = docker.execCreate(containerId, new String[]{ "/opt/couchbase/bin/couchbase-cli"