添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

在java中运行Docker命令

0 人关注

I'm trying to run this command in docker trough java, but i don't know why it only works when i execute the command in the host machine and not trough java (when execute on java it doesn't add or say nothing). i'm 99% sure problem are the ">>" of the echo but i don't know how to fix it.

    private void doCommand(){
    String command = "docker exec -i -t vsftpd bash -c 'echo -e \"myuser5\\nmypass\" >> /etc/vsftpd/virtual_users.txt'";
    try {
        ProcessBuilder pb = new ProcessBuilder(command);
        Process process = pb.start();
        InputStream inputStream = process.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        String line = null;
        while ((line = reader.readLine()) != null) {
            System.out.println(line);
    }catch (Exception e){
        e.printStackTrace();