Docker Shared folder on windows

Docker is ultra hot right now. It`s becoming a standard very quickly.  There are some issues on IO and Network but still a very promising solution for prime time. If you are a developer and are working on a Windows machine docker is great for you because you can have linux almost for free :-) For Mac and Windows users we need use Boot2Docker. Boot2Docker is a very small image lass them 30MB and is ultra fast it uses tiny linux kernel. Let`s see how to have a shared folder in windows and a docker container using ubuntu inside docker :-) This should be included at the official boot2docker image at some point but for now or you build the image or you do a workaround.




Getting VirtualBox

Make sure you have the latest version of virtualbox installed. Youcan download it here: https://www.virtualbox.org/wiki/Downloads

Getting Boot2Docker

First of all you need get boot2docker, here: https://github.com/boot2docker/windows-installer/releases current version now is 1.6.2. There only one problem, boot2docker does not have support for Virtual Box Guest Tools :(.  You can read more on this pull requests:

https://github.com/boot2docker/boot2docker/issues/43
https://github.com/boot2docker/boot2docker/issues/232
https://github.com/boot2docker/boot2docker/pull/534

Workaround to have the shared folder working on Windows

First of all you need download the image(you can build a more recent image if you want go check the links on the previous session) with virtualbox guest tools instaled, you can get it here: http://people.renci.org/~stealey/boot2docker/boot2docker.iso You will need do replace your boot2docker image with this one, i recomed you do a backup. Your boot2docker should be installed here: C:\Users\YOUR_USER\.boot2docker\boot2docker.iso

You will need stop boot2docker with $ boot2docker stop and them run the virtualbox command.

Them you will need create a script to use the VirtualBox API in order to create the shared folder.
C:\Progra~1\Oracle\VirtualBox\VBoxManage.exe %1 %2 %3 %4 %5 %6 %7 %8 %9
view raw vbm.bat hosted with ❤ by GitHub
With this script you can run it like this to create your shared folder:
vbm sharedfolder add boot2docker-vm -name home -hostpath d:\shared\
view raw shared.bat hosted with ❤ by GitHub

Once you do that you can start boot2docker with

$ boot2docker start
$ boot2docker ssh

Mounting the shared folder on docker(boot2docker)

Start your boot2docker and them enter in your console and type:
sudo mount -t vboxsf home /home/docker/shared
view raw shared.sh hosted with ❤ by GitHub

A Little Bit of Inception

Let`s see i want to propagate this shared folder to another container inside docker, lets use a ubuntu image, you can do like this(now there is a docker command for it :-) ):
run -t -i -v /home/docker/shared/:/home/docker/shared ubuntu /bin/bash

Shared Folders with VirtualBox on Windows still slow :(. I did a simple benchmark running a simple Node.JS code on my windows and them on this ubuntu/docker and the performance with the shared folder is slow but it`s okay to have fun a learn docker. For something more professional i recommend you consider Docker-Machine with Amazon driver.

[simple.js]
var i, a, b, c, max;
max = 1000000000;
var d = Date.now();
for (i = 0; i < max; i++) {
a = 1234 + 5678 + i;
b = 1234 * 5678 + i;
c = 1234 / 2 + i;
}
console.log('NodeJS on docker :-) Beanchmark Result: ');
console.log((Date.now() - d) + ' ms to run.');
[Benchmark Results]
On windows:
$ node simple.js
NodeJS on docker :-) Beanchmark Result:
1121 ms to run.
On Linux/Docker:
$ root@480ad96da98a:/home/docker/shared/shared# js simple.js
NodeJS on docker :-) Beanchmark Result:
2352 ms to run.
view raw benchmark.txt hosted with ❤ by GitHub

Popular posts from this blog

Having fun with Zig Language

C Unit Testing with Check

Cool Retro Terminal