-1

So I have a Docker network that has a Docker file with a bunch of information. I have a java program that is going to bring up the enviorment and then produce several commands to run within this enviorment. To be clear, the first command I need to run is NOT inside the Docker enviorment. I am having some challenges with the Process and Runtime classes.

First, say I wanted my java program to launch a new gnome terminal and then run a command to get into the docker network. I have this command,

Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal"});

Gnome terminal sucessfully comes up but any additional arguments I give in this array are just ignored. For example,

Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","ls"});

Does not work. The command I ultimatly want to run would look something like this,

Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","sudo","docker","exec","-it","sawtooth-shell-default", "bash"});

Second, Once I have this running, will additional commmands I run work within the Docker enviorment? I have a python file with a Stream handler that specifies the correct commands to run. Other documentation on related issues was limited.

I made sure my code was wrapped in a runtime exception try catch and that I was running the correct .class file. Any help on this would be great!

Edit: I have also tried to run this in another linux terminal like Hyper and Tilda

I also am able to get a sudo sign in when I run the command like so,

Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","--","sudo","docker","exec","-it","sawtooth-shell-default", "bash"});

However it closes immediatly after authorizing.

  • 1
    Try `Process process = Runtime.getRuntime().exec(new String[]{"gnome-terminal","--","ls"});` also, running a gnome-terminal in a docker image seems like the wrong way to go about things. – Elliott Frisch Jul 15 '22 at 16:29
  • If you are running that command from a Java process running inside a Docker image, then you are also running that command inside the Docker image. – Mark Rotteveel Jul 15 '22 at 17:02

1 Answers1

0

Okay this is what I was attempting to do. https://www.atlassian.com/blog/software-teams/deploy-java-apps-with-docker-awesome This site is outdated and I had to use this link for getting that latest version of the java PPA.

This process basically installs java into the docker contatiner so that I can run a java program that uses Runtime.