I'm trying to run an Ubuntu image from a java program using a script; here is how:
my java code:
public static void main(String[] args) {
executeCommand("/home/abrahem/IdeaProjects/untitled3/src/createContainer.sh");
}
public static void executeCommand(String filePath) {
File file = new File(filePath);
if (!file.isFile()) {
throw new IllegalArgumentException("The file " + filePath + " does not exist");
}
try {
if (isLinux()) {
Process p = Runtime.getRuntime().exec("sh " + filePath);
p.waitFor(); // i tried to remove this but still not work for my me
} else if (isWindows()) {
Runtime.getRuntime().exec("cmd /c start " + filePath);
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
here is my createContainer.sh script file:
#!bin/sh
sudo docker run ubuntu
when I go to bin and type:
docker ps
or
docker ps -a
It should show the running Ubuntu container, but it doesn't.
Note: there is nothing wrong with the shell location; I try to create file in shell file and it works.
sudo docker run --name myubuntu -itd ubuntutry this instead.