Description
Hi all.
I threw a socket, and configured the client. 3.3.0 lib version.
To make sure the settings are correct, I run the command:
List<Container> containers = dockerClient.listContainersCmd().exec();
and I get the expected result. OK.
I need to execute a command from one container to another, and get the result in a text variable, if any:
public String execCommand(String containerId, String command) {
log.debug("Running command: " +command+ "in container: "+containerId);
String execId = dockerClient.execCreateCmd(containerId).withCmd(command).withAttachStdout(true).withAttachStderr(true).exec().getId();
final StringBuilder output = new StringBuilder();
dockerClient.execStartCmd(execId).exec(new ResultCallback.Adapter<Frame>() {
@Override
public void onNext(Frame object) {
output.append(new String(object.getPayload(), UTF_8));
super.onNext(object);
}
});
log.debug("Result of command: " +command+ " in container: "+containerId+" OUTPUT: "+output);
return output.toString();
}
The function compiles and runs without error, but I don't get anything in the output variable.
Suppose I would like to execute the equivalent of docker exec 222222222222 sh -c 'cd /etc/ && ls' through my client and get the result. How can I do it?
Why is my code not getting a return? What am I doing wrong? How should I reason when sending a command to another container?
PS sorry for google translate