从 java 程序执行 docker 命令时出错
Getting error while executing the docker command from java program
我尝试从 Java 代码执行以下 docker 命令:
command: ***docker exec -it reverent_hoover date***
(这里,reverente_hoover
是容器名称。)
当我从 Linux 执行上述命令时,它给了我以下输出:
Wed May 6 05:19:28 UTC 2015
但是当我尝试从 Java 代码执行它时,它给了我这个错误:
time="2015-05-05T19:31:19+05:30" level="fatal" msg="cannot enable tty
mode on non tty input"
我不知道如何解决这个问题。
Issue 10734 提及:
The java process is not providing a TTY to the docker CLI but you've asked for a TTY by specifying -t
in your command.
So, does the image actually need a TTY? If not, don't specifiy -t
... if the image doesn't need stdin at all don't specify -i
either.
If it does need the TTY, then you'll need to setup the TTY for your command and it should work.
例如,参见“persistent local tty session with java”
Instead of Runtime.getRuntime().exec("command");
do Runtime.getRuntime().exec("/bin/sh");
and hold on to the Process
object
"Runtime.exec with Unix console programs" 说明在使用 less
:
的上下文中
Process p = Runtime.getRuntime().exec(new String[] {"sh", "-c",
"less >/dev/tty"});
OutputStream out = p.getOutputStream();
out.write("Lengthy message".getBytes());
out.close();
System.out.println("=> "+p.waitFor());
我尝试从 Java 代码执行以下 docker 命令:
command: ***docker exec -it reverent_hoover date***
(这里,reverente_hoover
是容器名称。)
当我从 Linux 执行上述命令时,它给了我以下输出:
Wed May 6 05:19:28 UTC 2015
但是当我尝试从 Java 代码执行它时,它给了我这个错误:
time="2015-05-05T19:31:19+05:30" level="fatal" msg="cannot enable tty mode on non tty input"
我不知道如何解决这个问题。
Issue 10734 提及:
The java process is not providing a TTY to the docker CLI but you've asked for a TTY by specifying
-t
in your command.
So, does the image actually need a TTY? If not, don't specifiy-t
... if the image doesn't need stdin at all don't specify-i
either.If it does need the TTY, then you'll need to setup the TTY for your command and it should work.
例如,参见“persistent local tty session with java”
Instead of
Runtime.getRuntime().exec("command");
doRuntime.getRuntime().exec("/bin/sh");
and hold on to theProcess
object
"Runtime.exec with Unix console programs" 说明在使用 less
:
Process p = Runtime.getRuntime().exec(new String[] {"sh", "-c",
"less >/dev/tty"});
OutputStream out = p.getOutputStream();
out.write("Lengthy message".getBytes());
out.close();
System.out.println("=> "+p.waitFor());