If you want to use Tensorflow on a regular basis, there is no good performing alternative to using a native linux or Mac OS installation due to the lack of GPU support. Windows users who just want to take a glimpse at Tensorflow for learning or smaller research purposes however can do so easily by using Docker.
With the following setup, Tensorflow can be used on Windows hosts by using a docker-hostet Jupyter Notebook (former iPython Notebook) from the host browser with local .ipynb files.
Requirements
First, the following software has to be installed on the host. For those never worked with Docker, this short tutorial gives a good overview.
This setup tutorial is based on following path entries:
- C:\Program Files\Docker Toolbox
- C:\Program Files\Oracle\VirtualBox
1. Create and configure Docker-Machine
First we have to create and afterwards we configure a new local docker-machine.
1 |
docker-machine create --driver virtualbox default |
Next we have to forward ports 8888 (Jupyter NB) and 6006 (TensorBoard) to be able to use Jupyter Notebook and TensorBoard host-sided:
1 |
VBoxManage controlvm default natpf1 " jupyter_fw,tcp,127.0.0.1,8888,,8888" |
1 |
VBoxManage controlvm default natpf1 " tensorBoard_fw,tcp,127.0.0.1,6006,,6006" |
Instead of using VBoxManage you can use VirtualBox Manager by clicking Docker-Machine-VM->Settings->Network-Port Forwarding.
The next step is to share our hosts folder for .ipynb files. Therefore we have to stop the freshly created Docker-Machine and afterwards share the folder (in my case “jupyter_notebooks”) with the docker-machine by using the VBoxManage sharedfolder add command.
1 |
docker-machine stop default |
1 |
VBoxManage sharedfolder add default -name win_notebooks -hostpath C:\Users\...\jupyter_notebooks --automount |
Like above, instead of VBoxManage you can use the VirtualBox Manager here: VM->Settings->Shared Folders->add
2. Start Docker-Machine and “wire up” the shared folders.
By using the following two commands, we start the preconfigured machine and connect to it via ssh.
1 |
docker-machine start default |
1 |
docker-machine ssh default |
Afterwards we create a target folder inside of the docker-machine and mount the previously shared folder.
1 |
sudo mkdir /VM_notebooks |
1 |
sudo mount -t vboxsf win_ notebooks /VM_notebooks |
Now you should be able to list the shared folders contents with
1 |
ls /VM_notebooks |
3. Run Docker
As last step we can now create our docker container. Like before we forward ports 8888 and 6006 to the container by using the -p flag and again we share our folder by using -v. the source for our container is b.gcr.io/tensorflow/tensorflow from Google Container Registry. With -c we finally give the order to run Jupyter Notebook on our double-shared folder.
1 |
docker run -p 8888:8888 -p 6006:6006 -v /VM_notebooks:/notebooks --name "jupyter" b.gcr.io/tensorflow/tensorflow sh -c "jupyter notebook /notebooks" |
Once the sources are pulled, the container is created and Jupyter is started we can open the Notebook from our host browser with localhost:8888 and have Fun with Tensorflow.