Run a TensorFlow jupyter notebook on docker
This is getting started guide for ML beginners who wants to use Jupyter Notebook on Docker environment.
Docker is a way to use different development environments and frameworks without physically install them on your PC or workstation. For more information, please visit docker website.
TensorFlow is Machine Learning library where you can train your own ML model and develop AI modules
This guide based on Windows version
Install the Docker client
Install Docker desktop client, then we need to run a docker command to download the TensorFlow docker image.
docker pull tensorflow/tensorflow:latest # Download latest stable image
Open the docker client and visit the image tab, will show the image.
Running the Tensor container
To work with the image, we need to run container. On the command prompt run the docker run command.
docker run -it -p 8888:8888 tensorflow/tensorflow:latest-jupyter # Start Jupyter server
It will start the Jupiter notebook on the browser. Try creating a new Notebook and run the cell. Is it working.
All the Notebook you created are stored in tf folder inside the container. Go to the docker client - > click on the container tab - > click container Name -> Files -> tf, all your files were stored in this location.
Store Notebook on Local drive using Volume
Is it a way to sync the notebooks to a local drive? Yes.
We have to chain the volume option in our docker run command. Use full path instead of relative path while specifying the local path.
docker run -it -p 8888:8888 -v d:/src/tensor:/tf/ tensorflow/tensorflow:latest-jupyter # Start Jupyter server
The first argument to volume option (-v) is the target and the second is the source. All the files were sync between the container and the local drive.
Let's run the command and try to print tensor version by creating new jupyter notebook with following code
import tensorflow as tf;print(tf.__version__)
See the src\tensor\ folder, the synced notebooks were stored here. Try to change the file which will automatically update the container version too.
I hope this will helps.
Comments
Post a Comment