java 中调用docker_如何通过Java程序执行docker命令
我不需要调用Docker远程API,而是需要开发一个与Docker Linux Client(而不是Docker守护进程)对话的程序.这是我的代码try {String[] command = {"docker", "run", "-it", "tomcat:9", "bash"};ProcessBuilder pb = new ProcessBuilder(command);pb.inherit
我不需要调用Docker远程API,而是需要开发一个与Docker Linux Client(而不是Docker守护进程)对话的程序.这是我的代码
try {
String[] command = {"docker", "run", "-it", "tomcat:9", "bash"};
ProcessBuilder pb = new ProcessBuilder(command);
pb.inheritIO();
Process proc = pb.start();
InputStream is = proc.getInputStream();
OutputStream os = proc.getOutputStream();
BufferedReader reader
= new BufferedReader(new InputStreamReader(is));
BufferedWriter writer
= new BufferedWriter(new OutputStreamWriter(os));
writer.write("pwd");
writer.flush();
String line = "";
while ((line = reader.readLine()) != null) {
System.out.print(line + "
");
}
proc.waitFor();
} catch (Exception e) {
e.printStackTrace();
}
我总是得到错误.
如果我使用“-it”,它会说“无法在非tty输入上启用tty模式”,如果我使用“-i”,我将获得Stream Closed Exception.
有什么方法可以解决这个问题吗?
更多推荐
所有评论(0)