package org.opencb.commons.utils;

import org.apache.commons.lang3.tuple.Pair;
import org.opencb.commons.exec.Command;

import java.util.List;

public class DockerUtils {

    public static void run(String image, List<Pair<String, String>> bindings, String params) {
        // Docker run
        StringBuilder commandLine = new StringBuilder("docker run ");

        // Mount management (bindings)
        for (Pair<String, String> binding : bindings) {
            commandLine.append("--mount type=bind,source=\"").append(binding.getLeft()).append("\",target=\"").append(binding.getRight())
                    .append("\" ");

        }

        // Docker image and version
        commandLine.append(image).append(" ");

        // Params
        commandLine.append(params);

        // Execute command
        Command cmd = new Command(commandLine.toString());
        cmd.run();
    }
}

@@ -28,16 +28,60 @@
 utils;%0A%0A
+import org.apache.commons.lang3.ArrayUtils;%0A
 import o
@@ -209,16 +209,398 @@
 tils %7B%0A%0A
+    /**%0A     * Create and run the command line to execute the docker image.%0A     *%0A     * @param image Docker image name%0A     * @param user  Array of two strings: the first string, the user; the second, the group%0A     * @param bindings Array of bind mounts for docker volumes: source-target pairs%0A     * @param params Image command parameter%0A     * @return The command line%0A     */%0A
     publ
@@ -613,12 +613,14 @@
 tic 
-void
+String
  run
@@ -633,16 +633,31 @@
 g image,
+ String%5B%5D user,
  List%3CPa
@@ -792,24 +792,274 @@
 er run %22);%0A%0A
+        // User%0A        if (ArrayUtils.isNotEmpty(user)) %7B%0A            String u = user%5B0%5D;%0A            if (user.length %3E 1) %7B%0A                u += (%22:%22 + user%5B1%5D);%0A            %7D%0A            commandLine.append(%22-u %22).append(u).append(%22 %22);%0A        %7D%0A%0A
         // M
@@ -1422,17 +1422,31 @@
      // 
-P
+Image command p
 arams%0A  
@@ -1584,16 +1584,56 @@
 d.run();
+%0A%0A        return commandLine.toString();
 %0A    %7D%0A%7D

add 'user' parameter to the DockerUtils.run(), #45