pinesh shah pinesh shah - 1 year ago 180
Bash Question

Launching Docker demon from Java Service

Trying to launch a docker container in demon mode using shell script from java service deployed on Tomcat, on an ubunty based VM.

I have a java based REST service which has been deployed on tomcat, on the same VM i have installed Docker. I have created a shell file to launch my docker container. When execute this shell file from terminal it works perfectly fine. Although when i execute this shell file from java somehow it doesnt give any error and doesnt execute the docker command inside the shell file.

Note sure if I have missed a point, or have done something wrong. Would be greate if someone can help me.

Shell File Code snippet.(for testing currently have given Executed permission to all users using chmod 777)

echo First Parameter is $1
echo Second Parameter is $2
echo Third Parameter is $3
sudo docker run -d -e PARAM1=$1 -e PARAM2=$2 -e PARAM3=$3 --name=$1 <docker_iamge_name>

Java Codesnippet for calling the script file (note this is not a standalone java class I am using this code snippet inside on Java based REST service which is deployed on Tomcat)

String command[];
command = new String[] {"/home/launcher/","Param1","Param2", "Param3"};
Process process = Runtime.getRuntime().exec(command);

On Executing the above javascript in the Tomcat sdtout logs get the following

First Parameter is Param1
Second Parameter is Param2
Third Parameter is Param3

Post which if I check the docker ps -a, I dont see the container getting launched.

Thanks for Response.

Answer Source

I think your problem is that you are trying to use sudo in your

To understand what really has happened with a spawned process, you need to read both process.getInputStream() and process.getErrorStream(). The last one will show you exact error (if there was any).

In your case you should get something like:

sudo: no tty present and no askpass program specified

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download