docker jupyter

Docker Jupyter | How to install jupyter notebooks quickly using docker [2022]

Jupyter notebook is an excellent application used by many companies and developers to quickly combine code, documentation, and visuals in an interactive document. We can easily edit and share the notebook based on the need. In this blog, I will explain how to get started with docker jupyter notebook and will go over:

  • What is a jupyter notebook?
  • What are the advantages and disadvantages of a jupyter notebook?
  • What all jupyter notebooks are available.
  • We will install a few useful notebooks and try basic commands.
  • A few extra tips.

Now let’s get started with what a jupyter notebook is.

What is a jupyter notebook?

As per jupyter.org, The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations, and narrative text. Uses include data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.

Let’s further understand a few advantages and disadvantages of the jupyter notebook.

Advantages of jupyter notebook

Jupyter notebook provides many advantages; below, I have listed a few of them.

  • We can easily visualize the data in the jupyter notebook itself there is no need to install any separate tool for data visualization.
  • Code can be shared easily with jupyter notebooks. you can easily view code, execute it, and display the output directly in your notebook itself.
  • Jupyter Notebooks come in handy if we wish to prepare documentation. We can easily create the documentation with the notebook.
  • Jupyter notebooks are not static it means we can edit the code, delete the code and even rerun the code based on the need.

Limitations of jupyter notebook

Although the jupyter notebook has plenty of advantages, it has a few limitations as well; some of them are:

  • Sometimes It is very hard to test long tasks.
  • Running Jupiter notebook standalone is Less secure.
  • If you run any cell multiple times, a cell will be out of order.
  • There is no support for any IDE integration, lining, or code-style correction.

Now we understand the advantages and disadvantages of jupyter notebooks; let’s further check what jupyter notebooks are available in jupyterhub.

How many docker Jupyter notebooks are available?

There are many ready-to-use docker jupyter notebooks are available in dockerhub. You can use these available notebooks to deploy the jupyter instance quickly.

To get the list of available jupyter notebooks, go to Dockerhub and search for the jupyter notebooks.

Dockerhub Jupyter

There are approx. 12k ready-to-use notebooks available. Out of these the most used notebooks are:

  • jupyter/scipy-notebook
  • jupyter/datascience-notebook
  • jupyter/tensorflow-notebook
  • jupyter/all-spark-notebook
  • jupyterhub/jupyterhub

This tutorial will install some of the above notebooks and try some basic commands. Let’s first start with a scipy jupyter notebook.

Install scipy docker jupyter notebook

To install the jupyter notebook using docker, make sure docker is installed in your system. Let’s verify that the docker is running:

➜ docker --version
Docker version 20.10.3, build 48d30b5

Now pull the jupyter image from the dockerhub. It might take a few minutes to download the image from dockerhub.

➜  docker pull jupyter/scipy-notebook
Using default tag: latest
latest: Pulling from jupyter/scipy-notebook
345e3491a907: Pull complete
57671312ef6f: Pull complete
5e9250ddb7d0: Pull complete
e1fadee31091: Pull complete
70fa05f53554: Pull complete
4f4fb700ef54: Pull complete
80d0a768e52d: Pull complete
b8e1ae373de6: Pull complete
c13247cfb65f: Pull complete
eddf77815124: Pull complete
35ffc5e5dc79: Pull complete
97e18716b9a2: Pull complete
cdca71acba1b: Pull complete
c8469b528abe: Pull complete
fa53d08fc996: Pull complete
99cac836faeb: Pull complete
5f8cc05626db: Pull complete
c40336035c20: Pull complete
e03bfd4d9306: Pull complete
24020b1ee2d6: Pull complete
Digest: sha256:bb88f28940581b4729d01f18c62fb1e215f99ca0ab2977ecc9631417420b0161
Status: Downloaded newer image for jupyter/scipy-notebook:latest
docker.io/jupyter/scipy-notebook:latest

We have pulled a jupyter-SciPy notebook. So with the help of this notebook, we can perform scipy operations in this notebook.

For people who are not aware of scipy, it is an open-source python library mainly used for scientific and technical computing.SciPy contains optimization, linear algebra, integration, interpolation, image processing, ODE solvers, and other tasks common in science and engineering. To get more information about scipy, visit this link.

Now let’s run the docker image.

docker run -p 8888:8888 jupyter/scipy-notebook
WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
Executing the command: jupyter notebook
[I 14:45:35.105 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 2021-06-09 14:45:38.121 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 14:45:38.122 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 14:45:38.123 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 14:45:38.125 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2021-06-09 14:45:38.147 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.9/site-packages/jupyterlab
[I 2021-06-09 14:45:38.148 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 14:45:38.163 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 14:45:38.164 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 14:45:38.166 NotebookApp] http://f7e880dcefd7:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682
[I 14:45:38.167 NotebookApp]  or http://127.0.0.1:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682
[I 14:45:38.170 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 14:45:38.221 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/nbserver-7-open.html
    Or copy and paste one of these URLs:
        http://f7e880dcefd7:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682
     or http://127.0.0.1:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682

As instructed from the above output, let’s go to

http://127.0.0.1:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682 to access jupyter notebook.

If you are getting below the screen, it means your installation is successful

scipy docker jupyter notebook

Create notebook

To create a new notebook, Goto New>Python3

scipy docker jupyter notebook

The below screen will be opened in a new window with a notebook name untitled.

scipy docker jupyter notebook

If you wish to change the notebook name, click on the untitled and change name as per your need. For this demo, I am renaming the notebook as naivetech-demo1.

scipy docker jupyter notebook

Run Jupyter notebook

Now let’s type your first command, “print(“hello-world”),” and click on the run button to run the notebook.

docker jupyter notebook

Type a comment in the notebook followed by the ### sign to add a comment.

docker jupyter notebook

Click on Markdown and Run the cell.

docker jupyter notebook

Now let’s try a few more commands in the jupyter notebook.

linear algebra notebook

Similarly, you can try a few other tutorials.

Save notebook

If you wish to save your notebook. Goto file> Download as > pdf

jupyter notebook save

You can download the notebook in various formats and share it with other people.

Stop a jupyter notebook

If you wish to stop the jupyter notebook, open another window in the command line.

Check how many containers are running.

➜ docker ps
CONTAINER ID   IMAGE                    COMMAND                  CREATED             STATUS                 PORTS                              NAMES
f7e880dcefd7   jupyter/scipy-notebook   "tini -g -- start-no…"   About an hour ago   Up About an hour       0.0.0.0:8888->8888/tcp             eloquent_mestorf

Get the container id from the above command and type the below command to stop the jupyter container.

➜  ~ docker kill f7e880dcefd7
f7e880dcefd7

Try to access the below URL again. It won’t be accessible anymore.

http://127.0.0.1:8888/?token=f2e0ebe6f5cdf2ae60217acb8f4e01a30f785e85ee255682

Now we are done with the scipy notebook. Let’s proceed further and install a data science notebook

Install Jupyter data science jupyter notebook

The data science notebook comes with preinstalled python, sklearn, pandas, NumPy, and a few other essential libraries.

Run the below command to set up a jupyter data science notebook.

➜  docker run -p 8888:8888 jupyter/datascience-notebook
WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
Executing the command: jupyter notebook
[I 16:15:47.280 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 2021-06-09 16:15:53.193 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:15:53.194 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:15:53.194 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:15:53.194 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2021-06-09 16:15:53.320 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.9/site-packages/jupyterlab
[I 2021-06-09 16:15:53.327 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 16:15:53.399 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 16:15:53.399 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 16:15:53.399 NotebookApp] http://d749379a59b1:8888/?token=8dbe08adfba01139080942335d9764accfe19a4d43ca35dc
[I 16:15:53.400 NotebookApp]  or http://127.0.0.1:8888/?token=8dbe08adfba01139080942335d9764accfe19a4d43ca35dc
[I 16:15:53.400 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 16:15:53.503 NotebookApp]

    To access the notebook, open this file in a browser:
        file:///home/jovyan/.local/share/jupyter/runtime/nbserver-8-open.html
    Or copy and paste one of these URLs:
        http://d749379a59b1:8888/?token=8dbe08adfba01139080942335d9764accfe19a4d43ca35dc
     or http://127.0.0.1:8888/?token=8dbe08adfba01139080942335d9764accfe19a4d43ca35dc

Follow the instruction mentioned in the console output to access the web UI.

Now let’s create a new python notebook

data science jupyter notebook

Now let’s try to run a simple data science model

data science jupyter notebook

And you can see data science packages readily available in this installation. We don’t need to set up anything else apart from this to get started. This is very useful if you want to quickly try out a few models without worrying about tools and the dependent packages.

Let’s kill this data science jupyter notebook and try another notebook

➜  docker ps
CONTAINER ID   IMAGE                          COMMAND                  CREATED          STATUS                   PORTS                              NAMES
d749379a59b1   jupyter/datascience-notebook   "tini -g -- start-no…"   15 minutes ago   Up 15 minutes            0.0.0.0:8888->8888/tcp             elated_galois

➜  docker kill d749379a59b1
d749379a59b1

Install Jupyter TensorFlow notebook

Tensorflow is an open-source AI library that uses data flow graphs to build models. It allows developers to create large-scale neural networks with multiple layers. TensorFlow is used primarily for Classification, Perception, Understanding, Discovering, and Prediction.

Run the below command to set up the TensorFlow notebook.

docker run -p 8888:8888 jupyter/tensorflow-notebook
Unable to find image 'jupyter/tensorflow-notebook:latest' locally
latest: Pulling from jupyter/tensorflow-notebook
345e3491a907: Already exists
57671312ef6f: Already exists
5e9250ddb7d0: Already exists
e1fadee31091: Already exists
70fa05f53554: Already exists
4f4fb700ef54: Already exists
80d0a768e52d: Already exists
b8e1ae373de6: Already exists
c13247cfb65f: Already exists
eddf77815124: Already exists
35ffc5e5dc79: Already exists
97e18716b9a2: Already exists
cdca71acba1b: Already exists
c8469b528abe: Already exists
fa53d08fc996: Already exists
99cac836faeb: Already exists
5f8cc05626db: Already exists
c40336035c20: Already exists
e03bfd4d9306: Already exists
24020b1ee2d6: Already exists
3ace684ab257: Pull complete
Digest: sha256:41a30c35ad7a1aa118a0690547d0e26c605d2dd8a7876a198255054f24731080
Status: Downloaded newer image for jupyter/tensorflow-notebook:latest
WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice.
Executing the command: jupyter notebook
[I 16:39:09.963 NotebookApp] Writing notebook server cookie secret to /home/jovyan/.local/share/jupyter/runtime/notebook_cookie_secret
[W 2021-06-09 16:39:19.670 LabApp] 'ip' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:39:19.671 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:39:19.671 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[W 2021-06-09 16:39:19.671 LabApp] 'port' has moved from NotebookApp to ServerApp. This config will be passed to ServerApp. Be sure to update your config before our next release.
[I 2021-06-09 16:39:19.734 LabApp] JupyterLab extension loaded from /opt/conda/lib/python3.9/site-packages/jupyterlab
[I 2021-06-09 16:39:19.734 LabApp] JupyterLab application directory is /opt/conda/share/jupyter/lab
[I 16:39:19.780 NotebookApp] Serving notebooks from local directory: /home/jovyan
[I 16:39:19.781 NotebookApp] Jupyter Notebook 6.4.0 is running at:
[I 16:39:19.782 NotebookApp] http://a36a0722dca8:8888/?token=a6c0f54750e9fcbd253d30cc4403d69020d5f2c3e9f17de6
[I 16:39:19.783 NotebookApp]  or http://127.0.0.1:8888/?token=a6c0f54750e9fcbd253d30cc4403d69020d5f2c3e9f17de6
[I 16:39:19.785 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Go to http://127.0.0.1:8888/?token=a6c0f54750e9fcbd253d30cc4403d69020d5f2c3e9f17de6 to access the TensorFlow notebook.

docker TensorFlow notebook

Now let’s create a new python notebook.

For this demo, I will be using mnist data set to train the model. To get more information about the mnist dataset, follow this link:

Try importing TensorFlow and train some models using the mnist dataset.

tensorflow jupyter notebook

Conclusion

Finally, we have come to the end of this fantastic tutorial. We started with the basics of the jupyter notebook, and we went deep dive and installed scipy, data science, and the TensorFlow library. We have also seen some of the advantages and disadvantages of the jupyter notebook. I hope you like this tutorial. Please do let me know in the comment box, and I will be more than happy to get your feedback.

Happy learning:)

More to read?

Docker layers

Which docker base image to use

What docker images are available

1 thought on “Docker Jupyter | How to install jupyter notebooks quickly using docker [2022]”

  1. Top notch post. I learn a new generation on different blogs everyday. Selecting stimulating to learn content from other writers and study a little something from. I want to apply certain about this content on my blog allow me to explain mind. Natually Ill given a link on your site. Great sharing.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top