How to perform Runtime.getRuntime().exec from docker container

30 views Asked by At

I have code to open a link in a browser. I need to run application with docker, but just calling Runtime.getRuntime().exec(...) executes it inside the Docker container. How can I open the link inside docker container?

if (SystemUtils.IS_OS_LINUX) {
   // Workaround for Linux because "Desktop.getDesktop().browse()" doesn't work on some Linux implementations

    if (Runtime.getRuntime().exec(new String[] { "which", "xdg-open" }).getInputStream().read() != -1) {
       Runtime.getRuntime().exec(new String[] { "xdg-open", url });
    } else {
        log.warn("Error when opening a tab in a browser for Linux OS");
    }
 } else {
    if (Desktop.isDesktopSupported()) {
        Desktop.getDesktop().browse(new URI(url));
     } else {
        log.warn("Error when opening a tab");
     }
}

I am trying to add browser to docker container, but as far as I understand this cannot be done.

0

There are 0 answers