The base docker image is a bare bones ubuntu server install. We’re going to use that as a base and create our own image with node installed.
In case you’d rather just watch check out the screencast: http://youtu.be/KkSbEvuRbfo
Step 1) Open a terminal and start an instance using the base image. This will launch you into a shell where we can begin to customise the image:
$ sudo docker run -i -t base /bin/bash
Step 2) Install node:
$ apt-get update
$ apt-get install python-software-properties python g++ make
$ apt-get install nodejs
Note: replace the `python-software-properties` package with `software-properties-common` on Ubuntu 12.10 and above.
Step 3) Next bake our own image. Open another terminal session leaving the other one active in the background, then:
$ sudo docker ps
This should show the ID of the running container in the other terminal. Copy it then run:
$ sudo docker commit <paste your container ID here> nodejs
Step 4) Check that the image was created:
$ sudo docker images
If all went to plan you should now be able to see your new image called “nodejs” appearing in the list.
Step 5) Run some code inside your new sandbox:
$ echo "console.log('Hello World');" | sudo docker run -i nodejs /bin/bash -c "cat > hello.js; nodejs hello.js"
And that’s all there is to it! You’ve just successfully run arbitrary code in a safe, secure sandbox. Better still, since it’s based on LXC there are options for setting resource quotas to limit CPU and Memory usage meaning that denial of service by resource starvation is now a thing of the past.
* Stolen mercilessly from the good people at kuhnza.com (http://kuhnza.com/2013/03/27/docker-makes-creating-secure-sandboxes-easier-than-ever/)
Theme by Danetsoft and Danang Probo Sayekti inspired by Maksimer