Monday, September 19, 2016

How to use TensorFlow on Windows via Docker

The support of Docker on Windows comes in two flavors. For native support, some version of Windows is required and it's still maturing, I would confess Hyper-V is a nice thing from the native Windows perspective, however it's too greedy on Memory. So for me just focus on Docker toolbox for Windows.

Before we begin, let's have a look at the architecture of Docker working principle on Windows, referring to the following figure[1]:


So general speaking, the host contained in a image called boot2docker which is running in a virtual machine (here it's called "default" running in VirtualBox). Docker daemon and any other containers run within the host.
So when manipulate with the command docker-machine, generally the parameter is always default, for example:
docker-machine start default
docker-machine stop default


After click the "Docker Quickstart Terminal", after a while for preparation (create the default virtual machine running in VirtualBox for the first time; or bring it to life if it's already exist. and start the deamon and communicate with it):



The host can be accessed by the pre-configured ssh setting:

Just typing ssh docker@127.0.0.1 -p 1939. The password is tcuser.

Here we can inspect some interesting settings.
1. The docker toolbox will create a host-only network interface for the "default" running instance:

It will be functioning at least to layer 3, so it gets an IP address, usually it's 192.168.99.1 from outside.
2. When you inspect inside from docker, it's quite interesting:
I know eth1 is corresponded to the newly create host-only network, to my understanding, the host-only network interface can be shared by many instances, so each should has their own specific IP address, so here it's 192.168.99.100

Notice the docker_gwbridge, as it name reflects, it's a bridge built on top of eth1. I guess it's got a IP address range 172.18.0.0/16 just for the flexibility. There's potentiality for existence of more such bridges.

Another interface docker0 is actually connected to this bridge. If you run more containers, one can guess that the virtual interface is also connected to docker_gwbridge, with IP addresses from 172.17.0.0/16.

Once such networking topology is made clear, it can ease some confusing problems.

For example, it's quite common for one runs container first then realize that export some port for external access is unavoidable. For example, if we just run the following command:
docker run --name tensorflow -it gcr.io/tensorflow/tensorflow:latest-devel
we will find later we cannot access TensorBoard, which is listening on the following address: 0.0.0.0:6006.

So one way is to remove the existing tensorflow container, and explicitly publish the port-mapping on creating:
docker rm tensorflow
docker run -p 6006:6006 --name tensorflow -it gcr.io/tensorflow/tensorflow:latest-devel

Another way is enter docker host, and manipulate the iptables (I guess it works, but I haven't try):


The command working with common container is simple, for example, start and stop a container:
docker stop tensorflow
docker start -ai tensorflow
In the above command, it's necessary to temporarily redirect stdin, stdout and stderr to the current terminal for convenience.


Once start a tensorflow docker instance, the following is just happy hacking!

No comments:

Post a Comment