Tensorflow Jupyter notebook on Docker

Machine Learning and Data Analytics are becoming quite popular for main stream data processing. In this article we learn how to run Tensorflow programs on Jupyter which is served from inside a docker container.

Setup Docker

we assume you have the latest version of docker running on your compute. In our case it is docker for mac https://docs.docker.com/docker-for-mac/install/

Make sure you have access to the docker binary

docker --version
Docker version 17.09.0-ce, build afdb6d4

Download Run Docker Jupyter Image

Run the jupyter/scipy-notebook in the detached mode. Please note the container port 8888 is mapped to host port of 8888.

docker run -d -p 8888:8888 jupyter/tensorflow-notebook

Output of the above command will show the CONTAINER_ID of the container

1a99981fa8443cf49290a8a58dad369a98bb56dd0602d84b23f846a8f87c00b5

You can inspect the container running and get the container id

docker ps -a

Output

CONTAINER ID        IMAGE                    COMMAND                  CREATED              STATUS                     PORTS                     NAMES
1a99981fa844        jupyter/tensorflow-notebook   "tini -- start-not..."   About a minute ago   Up About a minute           0.0.0.0:8888->8888/tcp    laughing_kowalevski

Get the Security token

Since the jupyter notebooks from this image have a security token associated, execute the following command to get the token

docker exec 4bdd0e4841e0 jupyter notebook list

Output of the command above will give the URL with security token

Currently running servers:

http://localhost:8888/?token=ad511431b170909ad5779c967f3d5650118ff7c02bb02664 :: /home/jovyan

Access Jupyter Notebook

  1. Direct the Host browser at the URL above http://localhost:8888/?token=a37c45becfd981ffeb2fdca9b82419bd697e9a8b4b5bf25b
../_images/jupyter_one.png ../_images/jupyter_np_two.png
  1. Create a new Python3 notebook
../_images/jupyter_np_three.png
  1. Add following basic Tensorflow code
../_images/jupyter_tf_run_sample.png
  1. Rename and save the notebook
../_images/jupyter_tf_rename.png

once the notebook is renamed - new name appears

../_images/jupyter_tf_renamed.png

Restart Docker and Check notebook still exists

docker stop 1a99981fa844

docker start 1a99981fa844
../_images/jupyter_tf_restarted.png

Summary

In this article we learnt how to use a Jupyter notebook running inside a docker image to run Tensorflow samples.