Skip to content

Instantly share code, notes, and snippets.

@ericjang
Last active March 27, 2021 22:19
Show Gist options
  • Star 54 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save ericjang/959c03168c0bdfac1ca3 to your computer and use it in GitHub Desktop.
Save ericjang/959c03168c0bdfac1ca3 to your computer and use it in GitHub Desktop.
Setting up TensorFlow on Windows using Docker.

TensorFlow development environment on Windows using Docker

Here are instructions to set up TensorFlow dev environment on Docker if you are running Windows, and configure it so that you can access Jupyter Notebook from within the VM + edit files in your text editor of choice on your Windows machine.

Installation

First, install https://www.docker.com/docker-toolbox

Since this is Windows, creating the Docker group "docker" is not necessary.

Launching TensorFlow

Open up "Docker Quickstart Terminal". It should bring up a MinGW-type shell. You could also use Windows cmd.exe or Powershell.exe but they haveadditional configurations that you need to do before you can run docker.exe

Launch the TensorFlow container. Set up port forwarding, mount contents of "thesis" directory into /home (the thesis folder doesn't show up, as its contents are mapped to the contents of /home.

$ docker run -it -p 8888:8888 -p 6006:6006 -v //c/Users/eric/Dropbox/thesis:/home b.gcr.io/tensorflow/tensorflow

The first time the command is run, it will Download and install TensorFlow. Afterwards, This should bring you into a Linux VM.

The command above mounts a folder in your Windows host machine into the container. It's preferable to do things this way, because the container does not persist your files by default.

It already comes with Jupyter installed, but you won't be able to access the notebooks by navigating to localhost:8888 (or whatever port Jupyter starts on). You will also want to expose port 6006 to be able to use TensorBoard (currently, exposing a port on a live container is not possible).

Instead, since it is running in a VM, not only do you need to forward the port (hence the -p 8888:8888), but the IP address you access needs to be the IP address of the VM, not the Windows Machine. Hence, you need to find the address of the docker machine running the container.

Listing the docker containers

$ docker ps
CONTAINER ID        IMAGE                            COMMAND             CREATED             STATUS              PORTS                              NAMES
4dd413d71153        b.gcr.io/tensorflow/tensorflow   "/bin/bash"         2 minutes ago       Up 2 minutes        6006/tcp, 0.0.0.0:8888->8888/tcp   lonely_engelbart
$ docker ps
docker-machine ls
$ docker-machine ls
NAME      ACTIVE   DRIVER       STATE     URL                         SWARM   ERRORS
default   *        virtualbox   Running   tcp://192.168.99.100:2376
$ docker-machine ip default
192.168.99.100

Navigate web browser to 192.168.99.100:8888 (or whatever webserver port your web app is running on) and you should be able to see your web apps.

Hacking on Source Code

Let's say you want to use this container for your research environment. You'll want to clone the docker container so you can make changes to it.

In the Docker Quickstart terminal,

docker pull b.gcr.io/tensorflow/tensorflow-full
$ docker images
REPOSITORY                            TAG                 IMAGE ID            CREATED             VIRTUAL SIZE
b.gcr.io/tensorflow/tensorflow-full   latest              edc3d721078b        3 weeks ago         2.284 GB
b.gcr.io/tensorflow/tensorflow        latest              217daf2537d2        4 weeks ago         652.6 MB
hello-world                           latest              0a6ba66e537a        7 weeks ago         960 B

Let's say you installed a python package like ipdb and want to commit changes. Just do:

docker commit lonely_engelbart ejang/tensorflow

Subsequently,

docker run ejang/tensorflow

Moar Terminals

If you want to attach another shell to the docker container:

docker exec -it lonely_engelbart bash

Increasing Memory on Docker Machine

The docker-VM provided has default 1G memory, which is not sufficient to run the MNIST/CNN examples. You can configure the resource limits of the default Docker-machine VM from Virtualbox.

See this page for more tips: http://blog.pavelsklenar.com/5-useful-docker-tip-and-tricks-on-windows/

@stevesiddals
Copy link

Thank you! Exactly what I was looking for.

@tomzx
Copy link

tomzx commented Jul 8, 2016

@ericjang Is this under Windows 7/8/10? Which version of docker? I'm not able to get the VM host to mount which is why I'm asking.

Thanks for the guide by the way!

@ellpri
Copy link

ellpri commented Aug 3, 2016

Thanks!! $ docker run -it -p 8888:8888 -p 6006:6006 -v //c/Users/eric/Dropbox/thesis:/home b.gcr.io/tensorflow/tensorflow
what is /home . which path should i give here?

@VedAustin
Copy link

VedAustin commented Oct 1, 2016

@ellpri: /home is the folder that will created in the docker container. In the 'home' folder it will contain items that were in the 'thesis' folder. 'home' can be replaced by any name of your choice.

@MartinBodocky
Copy link

I'm running it like :
docker run -m 4g -d -it -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow
but when I execute:
http://localhost:8888/notebooks/3_mnist_from_scratch.ipynb
step 25 specifically. I got : "The kernel appears to have died. It will restart automatically."

I assume this has crashed because it doesn't have enough resources, how much resources and how can I allocate to Docker image?

@gburachas
Copy link

Excellent! Does it work with NVidia's CUDA?
thanks

@tymakhadija
Copy link

hello, can any one here to help me to install tensorflow

@rockper
Copy link

rockper commented Dec 20, 2016

To use nVidia CUDA, get the GPU image:
tensorflow/tensorflow:latest-gpu
Also install nvidia-docker

@ilovejs
Copy link

ilovejs commented Jan 5, 2017

nvidia-docker is not working on windows . ..

@Boggartfly
Copy link

@ilovejs nvidia-docker does not currently work on Windows 7,8 or 10 since AFAIK only Windows Server 2016 provides PCI-e passthrough which most people will not be using. See #issue197

@sameertikoo
Copy link

I am getting the following error while downloading the tensorflow gpu image

Status: Downloaded newer image for b.gcr.io/tensorflow/tensorflow:latest==> ] 111.3MB/117.1MB
D:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: error while creating mount source path '/c/Users/eric/Dropbox/thesis': mkdir /c/Users/eric: protocol error.
3ea4a014aa1c: Download complete

@laisooliveira
Copy link

After run the firt command:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Get https://b.gcr.io/v2/tensorflow/tensorflow/manifests/latest: unknown: b.gcr.io domain is disabled. See https://cloud.google.com/container-registry/docs/support/deprecation-notices.

@rochishredsam
Copy link

b.gcr.io and bucket.gcr.io is deprecated, use gcr.io or us.gcr.io or asia.gcr.io or eu.gcr.io

Example $ docker run -it -p 8888:8888 -p 6006:6006 -v //c/Users/eric/Dropbox/thesis:/home gcr.io/tensorflow/tensorflow

@dscha09
Copy link

dscha09 commented Jul 5, 2018

@laisooliveira were you able to solve this?

After run the firt command:
C:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: Get https://b.gcr.io/v2/tensorflow/tensorflow/manifests/latest: unknown: b.gcr.io domain is disabled. See https://cloud.google.com/container-registry/docs/support/deprecation-notices.

@dscha09
Copy link

dscha09 commented Jul 5, 2018

@sameertikoo were you able to solve this?

I am getting the following error while downloading the tensorflow gpu image

Status: Downloaded newer image for b.gcr.io/tensorflow/tensorflow:latest==> ] 111.3MB/117.1MB
D:\Program Files\Docker Toolbox\docker.exe: Error response from daemon: error while creating mount source path '/c/Users/eric/Dropbox/thesis': mkdir /c/Users/eric: protocol error.
3ea4a014aa1c: Download complete

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment