1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| public static void execCommand(String containerId,String command){ ExecCreateCmdResponse execCreateCmdResponse = dockerClient.execCreateCmd(containerId).withAttachStdout(true).withAttachStderr(true).withCmd("bash", "-c", command).exec(); dockerClient.execStartCmd(execCreateCmdResponse.getId()).exec(new ResultCallback<Frame>() { @Override public void onStart(Closeable closeable) {
}
@Override public void onNext(Frame frame) { //如果这里输出了frame.toString(),就可以得到命令输出结果 }
@Override public void onError(Throwable throwable) {
}
@Override public void onComplete() {
}
@Override public void close() throws IOException {
} }); }
|