/etc/a" /> /etc/a" /> /etc/a"/>

I am trying to compile code in docker container and able to create the container but unable to get any data in the callback function

460 views Asked by At

Dockerfile

FROM chug/ubuntu14.04x64 

# Update the repository sources list
RUN echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list
RUN apt-get update
# RUN apt-get upgrade

# Install all the languages/compilers we are supporting.
RUN apt-get install -y gcc
RUN apt-get install -y g++
RUN apt-get install -y php5-cli
RUN apt-get install -y ruby
RUN apt-get install -y python
RUN apt-get install -y mono-xsp2 mono-xsp2-base

RUN apt-get install -y mono-vbnc
RUN apt-get install -y npm
RUN apt-get install -y golang-go    
RUN apt-get install -y nodejs

RUN npm install -g underscore request express jade shelljs passport http sys jquery lodash async mocha moment connect validator restify ejs ws co when helmet wrench brain mustache should backbone forever debug && export NODE_PATH=/usr/local/lib/node_modules/

RUN apt-get install -y clojure1.4


# prepare for Java download
RUN apt-get install -y python-software-properties
RUN apt-get install -y software-properties-common

# grab oracle java (auto accept licence)
RUN add-apt-repository -y ppa:webupd8team/java
RUN apt-get update
RUN echo oracle-java8-installer shared/accepted-oracle-license-v1-1 
select true | /usr/bin/debconf-set-selections
RUN apt-get install -y oracle-java8-installer


RUN apt-get install -y gobjc
RUN apt-get install -y gnustep-devel &&  sed -i 's/#define 
 BASE_NATIVE_OBJC_EXCEPTIONS     1/#define BASE_NATIVE_OBJC_EXCEPTIONS     
 0/g' /usr/include/GNUstep/GNUstepBase/GSConfig.h


RUN apt-get install -y scala
RUN apt-get install -y mysql-server
RUN apt-get install -y perl

RUN apt-get install -y curl
RUN mkdir -p /opt/rust && \
curl https://sh.rustup.rs -sSf | HOME=/opt/rust sh -s -- --no-modify-
path -y && \
chmod -R 777 /opt/rust

RUN apt-get install -y sudo
RUN apt-get install -y bc

RUN echo "mysql ALL = NOPASSWD: /usr/sbin/service mysql start" | cat >> /etc/sudoers

lang.js

module.exports={
  "1":"c",
  "2":"c++",
  "3":"erlang",
  "4":"pyhton2.7",
  "5":"python3",
  "6":"nodejs"
}

Method POST route /compile

var compileController={}; 
var lang=require('./lang');

var random=require('./random')

compileController.compile=function(req,res){
  var lang_id=req.body.id
  console.log(lang_id);

  if(lang_id in  lang){
    console.log("i  ma here")
    console.log(req.body)
    let sandBoxpath='./'+lang[lang_id]+'/sandBox'
    let sandBox=require(sandBoxpath);

    var language = req.body.id;
    var code = req.body.code;
    var stdin = req.body.stdin;

    var folder= '../../temp/' + random(10); 
    var path=__dirname+"/";

    var vm_name='virtual_machine';
    var timeout_value=20;
    var sandboxType = new sandBox(timeout_value,path,folder,vm_name,code,stdin);

    sandboxType.run(function(data,exec_time,err){

        res.send({output:data, langid: language,code:code, errors:err, time:exec_time});
    });
}else{
    res.json({message:"language not supported" })
}

}

- Sandbox details instantiating sandbox

var DockerSandbox = 
function(timeout_value,path,folder,vm_name,code,stdin_data){
    this.timeout_value=timeout_value;
    this.path=path;
    this.folder=folder;
    this.vm_name=vm_name;
    this.compiler_name="nodejs";
    this.file_name="file.js";
    this.code = code;
    this.langName="Nodejs";
    this.stdin_data=stdin_data;
}

creating folder and sharing the code with container

DockerSandbox.prototype.run = function(success){
   var sandbox = this;
   this.prepare( function(){
    sandbox.execute(success);
   });
}


DockerSandbox.prototype.prepare = function(success){
  var exec = require('child_process').exec;
  var fs = require('fs');
  var sandbox = this;

  exec("mkdir "+ this.path+this.folder+"&& chmod 777 "+this.path+this.folder,function(st){

     fs.writeFile(sandbox.path + sandbox.folder+"/" +sandbox.file_name, sandbox.code,function(err){

        if (err){
            console.log(err);
        }else{

            exec("chmod 777 \'"+sandbox.path+sandbox.folder+"/"+sandbox.file_name+"\'")
            fs.writeFile(sandbox.path + sandbox.folder+"/inputFile", sandbox.stdin_data,function(err){
                if (err){
                    console.log(err);
                }else{
                    success();
                } 
            });
        } 
    });

});
}

I'm trying to run codes inside the docker. I am unable to get the id of the container in this method although the container is getting created(accessible via docker stats)**

code

DockerSandbox.prototype.execute = function(success){
  console.log("getting printed")

  let exec = require('child_process').exec;
  exec('docker run -i --rm  -v foldepath:/code virtual_machine /bin/bash',function(error, stdout, stderr){
      console.log("Getting no data over here")

      console.log(error,stdout,stderr)
  })

}

 module.exports = DockerSandbox;
0

There are 0 answers