The "Docker Code Compiler" can be used to run adhoc code in a "sandboxed" mode. Basically, it brings up a temporary docker instance, runs your code and then returns any output/error generated after running the code. The library can run as a service or for a "single" run
You can use it to run any code in a sandbox so you don't risk untrusted sources messing up your server contents. A good example is an online code compiler application!
- Install go
- Checkout code in $GOPATH/src/github.com
Run Docker setup
cd docker_setup./BuildCompilerDockerImage.sh
Build Library
go build start.go
If you see errors like "undefined: client.NewClientWithOpts", run the following
go get github.com/docker/docker@master
Can be run in "service" OR "Local" mode
To run as service
`./start svc`
You can then Post requests to http://localhost:8090/api/compile
-
Java Example
curl -X POST \ http://localhost:8090/api/compile \ -d '{ "language": "java", "code": "class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello \" + args[0]);}}", "stdin": "World!" }' -
Python Example
curl -X POST \ http://localhost:8090/api/compile \ -d '{ "language": "python", "code": "print('\''Hello World!'\'')" }'
To run single instance
- Java Example
./start local java "class HelloWorld { public static void main(String[] args) { System.out.println(\"Hello \" + args[0]);}}" world! - Python Example
./start local python "print('Hello')"
Java
Python3
Python
PHP
Ruby
Scala
GoLang