Codetainer:基于瀏覽器的Docker容器
你可以通過Codetainer創建基于瀏覽器的代碼運行沙箱,可以方便地嵌入到你的Web 應用中。你可以把它當成是 codepicnic.com 的開源克隆版。
Codetainer以一個Web 服務運行,并且它還提供 API,你可以在HTML頁面終端實時完成來創建、查看和附加代碼到沙箱的這些操作。Codetainer后端基于 Docker以及其API來完成這一系列主要功能。
Codetainer采用Go語言開發
安裝:
要求:
Docker版本1.8以上
Go版本1.4以上
# set your $GOPATH go get github.com/codetainerapp/codetainer # you may get errors about not compiling due to Asset missing, it's ok. bindata.go needs to be created # by `go generate` first. cd $GOPATH/src/github.com/codetainerapp/codetainer # make install_deps # if you need the dependencies like godep make
執行完成將會創建./bin/codetainer
Docker
設置Docker監聽TCP端口
DOCKER_OPTS="-H tcp://127.0.0.1:4500 -H unix:///var/run/docker.sock"
codetainer
# Docker API server and port DockerServer = "localhost" DockerPort = 4500 # Enable TLS support (optional, if you access to Docker API over HTTPS) # DockerServerUseHttps = true # Certificate directory path (optional) # e.g. if you use Docker Machine: "~/.docker/machine/certs" # DockerCertPath = "/path/to/certs" # Database path (optional, default is ~/.codetainer/codetainer.db) # DatabasePath = "/path/to/codetainer.db"
運行實例:
$ sudo docker pull ubuntu:14.04 $ codetainer image register ubuntu:14.04 $ codetainer create ubuntu:14.04 my-codetainer-name $ codetainer server # to start the API server on port 3000
在WEB APP中嵌入codetainer:
1.把 codetainer.js 復制到webapp中;
2.網頁中包含codetainer.js和jquery,創建一個div標簽,作為存儲codetainer終端的框架:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>lsof tutorial</title> <link rel='stylesheet' href='/stylesheets/style.css' /> <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> <script src="/javascripts/codetainer.js"></script> <script src="/javascripts/lsof.js"></script> </head> <body> <div id="terminal" data-container="YOUR CODETAINER ID HERE"> </body> </html>
3.執行javascript腳本以從codetainer API服務加載codetainer:
$('#terminal').codetainer({ terminalOnly: false, // set to true to show only a terminal window url: "http://127.0.0.1:3000", // replace with codetainer server URL container: "YOUR CONTAINER ID HERE", width: "100%", height: "100%", });
* 參考: GitHub 編譯/0xroot 內容有所刪減,轉載請注明來自FreeBuf黑客與極客(FreeBuf.COM)
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!