使用Java要运行shell脚本将文件复制到docker会返回错误

我试图用Java来执行触发docker copy命令的shell脚本。 我试过的所有东西都返回了代码127(找不到命令)。

public static void main(String[] args) { System.out.println("Starting shell script"); String script = "SendToDocker.sh"; String scriptPath = "/path/"; try { Process awk = new ProcessBuilder("/bin/bash", scriptPath + script).start(); awk.waitFor(); BufferedReader reader = new BufferedReader(new InputStreamReader( awk.getInputStream())); String s; while ((s = reader.readLine()) != null) { System.out.println("Script output: " + s); System.out.println("output code: "+awk.exitValue()); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("Finished"); } 

SendToDocker.sh

 #!/bin/bash docker cp /path/asdf.csv 2d55a8445409:/ 

如果我在terminal上运行脚本,脚本工作得很好。 任何帮助/想法将不胜感激。

*)转到Dockerfile所在的目录

*)docker build -t your_app_name。

*)docker run -it your_app_name