How do I start tensorflow docker jupyter notebook
I've installed the tensorflow docker container on an ubuntu machine. The tensorflow docker setup instructions specify:
docker run -it b.gcr.io/tensorflow/tensorflow
This puts me into the docker container terminal, and I can run python and execute the Hello World example. I can also manually run .\run_jupyter.sh to start the jupyter notebook. However, I can't reach the notebook from host.
How do I start the jupyter notebook such that I can use the notebook from the host machine? Ideally I would like to use docker to launch the container and start jupyter in a single command.
For a Linux host Robert Graves answer will work, but for Mac OS X or Windows there is more to be done because docker runs in a virtual machine.
So to begin launch the docker shell (or any shell if you are using Linux) and run the following command to launch a new TensorFlow container:
docker run -p 8888:8888 -p 6006:6006 b.gcr.io/tensorflow/tensorflow ./run_jupyter.sh
Then for Mac OS X and Windows you need to do the following only once:
- Open VirtualBox
- Click on the docker vm (mine was automatically named "default")
- Open the settings by clicking settings
- In the network settings open the port forwarding dialog
- Click the + symbol to add another port and connect a port from your mac to the VM by filling in the dialog as shown below. In this example I chose port 8810 because I run other notebooks using port 8888.
- then open a browser and connect to http://localhost:8810 (or whichever port you set in the host port section
- Make your fancy pants machine learning app!
My simple yet efficient workflow:
TL;DR version:
- Open Docker Quickstart Terminal. If it is already open, run
$ cd
- Run this once:
$ docker run -it -p 8888:8888 -p 6006:6006 -v /$(pwd)/tensorflow:/notebooks --name tf b.gcr.io/tensorflow/tensorflow
- To start every time:
$ docker start -i tf
If you are not on windows, you should probably change
/$(pwd)
to$(pwd)
You will get an empty folder named tensorflow
in your home directory for use as a persistent storage of project files such as Ipython Notebooks and datasets.
Explanation:
-
cd
for making sure you are in your home directory. - params:
-
-it
stands for interactive, so you can interact with the container in the terminal environment. -
-v host_folder:container_folder
enables sharing a folder between the host and the container. The host folder should be inside your home directory./$(pwd)
translates to//c/Users/YOUR_USER_DIR
in Windows 10. This folder is seen asnotebooks
directory in the container which is used by Ipython/Jupyter Notebook. -
--name tf
assigns the nametf
to the container. -
-p 8888:8888 -p 6006:6006
mapping ports of container to host, first pair for Jupyter notebook, the second one for Tensorboard
-
-
-i
stands for interactive
Running TensorFlow on the cloud
After further reading of docker documentation I have a solution that works for me:
docker run -p 8888:8888 -p 6006:6006 b.gcr.io/tensorflow/tensorflow ./run_jupyter.sh
The -p 8888:8888 and -p 6006:6006 expose the container ports to the host on the same port number. If you just use -p 8888, a random port on the host will be assigned.
The ./run_jupyter.sh tells docker what to execute within the container.
With this command, I can use a browser on the host machine to connect to http://localhost:8888/ and access the jupyter notebook.
UPDATE: After wrestling with docker on windows I switched back to a Ubuntu machine with docker. My notebook was being erased between docker sessions which makes sense after reading more docker documentation. Here is an updated command which also mounts a host directory within the container and starts jupyter pointing to that mounted directory. Now my notebook is saved on the host and will be available next time start up tensorflow.
docker run -p 8888:8888 -p 6006:6006 -v /home/rob/notebook:/notebook b.gcr.io/tensorflow/tensorflow sh -c "jupyter notebook /notebook"
These steps worked for me if you are a total docker noob using a windows machine.
Versions: Windows 8.1, docker 1.10.3, tensorflow r0.7
- Run Docker Quickstart Terminal
- After it is loaded, note the ip address. If you can't find it use this
docker-machine ip
and make a note. Lets call it 'ip address'. Will look something like this: 192.168.99.104 (I made up this ip address) -
Paste this command on the docker terminal:
docker run -p 8888:8888 -p 6006:6006 b.gcr.io/tensorflow/tensorflow
.If you are running this for the first time, it will download and install the image on this light weight vm. Then it should say 'The Jupyter notebook is running at ....' -> This is a good sign!
- Open your browser at:
<your ip address (see above)>:8888
. Eg. 192.168.99.104:8888/ - Hopefully you can see your ipython files.