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.

  • Jenkins + Docker
  • Httplib2 exception raised when calling Twilio from python
  • Docker Pull Python
  • 'make' command not found in docker container
  • How long should I wait when I run `docker-compose up`? What should I do to retry?
  • How to remove entrypoint from parent Image on Dockerfile
  • 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)

    #!/bin/bash
    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/launcher_agent.sh","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.

  • What does Go Version means?
  • docker add “requires at least one argument” error
  • Cannot remove dead docker containers. Storage driver: btrfs
  • Running ipython notebook in a Docker Container
  • connecting to local mongodb from docker container
  • docker build fails - “cannot allocate memory”
  • One Solution collect form web for “Launching Docker demon from Java Service”

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

    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

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.