我想在Docker容器中编译代码,并能够创build容器,但无法获取callback函数中的任何数据
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" }
方法POST路由/编译
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" }) }
}
– 沙箱的细节 实例化沙箱
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; }
创build文件夹并与容器共享代码
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(); } }); } }); }); }
我试图在docker里面运行代码。 我无法得到在这个方法的容器的id,虽然容器正在创build(通过docker统计信息访问)**
码
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;
- 阻塞调用如何像Jetty Non Blocking IO servlet在内部处理数据库访问?
- 如何使用HTTP API从gcr.io Docker Registry列出图像和标签?
- 无法从Docker容器内部连接到Redis群集
- NodeJS + Forever + Dockerconfiguration不起作用
- 使用intellij远程debuggingnodejs
- 奇怪的ECONNRESET错误我无法弄清楚
- select一个GKE kubernetes集群的节点大小
- 在Windows上的Docker中安装节点模块在创build符号链接时失败
- “错误:未findlibsass绑定…”在nodejs中4.2.4 lts但不是5.4.1使用docker