Jupyter-based Projects
Get into the details of the Jupyter-based projects.
Before jumping right into the Jupyter-based projects and preparing a custom environment for that, we must know:
Jupyter Notebook
The Jupyter Notebook is an online tool that allows us to create and share interactive code documents. It provides a straightforward, simplified, document-centric environment.
Jupyter Notebooks have a file extension, i.e.,
.ipynb
.
Kernel
Kernels execute interactive code written in a specific programming language and deliver results to the user. Kernels also respond to requests for tab completion and introspection.
Environmental setup
To set up an environment for our Jupyter-based projects, we have to create the following files:
If additional context is required, consider reading Project Runtime and then return to this lesson.
Dockerfile and config.py files
We have to prepare a Dockerfile
with the required instructions and a config.py
file as follows:
# Fetching the Ubuntu 20.04 LTS imageFROM ubuntu:20.04# Making the apt-get installation non-interactiveARG DEBIAN_FRONTEND=noninteractive# Installing the Python & JupyterRUN apt-get -y -q update \&& apt-get -y -q install python3 python3-pip python-is-python3 \&& python -m pip install --no-cache-dir --upgrade pip jupyter \&& apt-get -y -q autoremove && apt-get -y -q autoclean# Adding the configuration fileADD config.py /root/.jupyter/jupyter_notebook_config.py
Dockerfile explained
-
Line 2: We are using the latest version of
Ubuntu 20.04 LTS
as the base image of our Dockerfile. -
Line 5: We are making apt-get installations non-interactive
-
Lines 8-11: We are updating the packages list, installing
python3
,pip
andjupyter
, and clearing up the packages list and related information to keep the image size as low as possible. -
Line 14: We are adding the configuration file for our notebooks. It contains preferences such as the port number (set to
8080
) and the notebook directory (specified to/usercode
).
Now that we have the required files, we can prepare a single tarball file of these files.
Make .tar.gz package
We need to compress the Dockerfile
and the config.py
files into a single tarball file. So in our terminal, we have to navigate to the directory where our files are present and use the following command to turn these assets into a tarball:
tar -czvf jupyterProject.tar.gz Dockerfile config.py
This command will take our Dockerfile
and config.py
files as inputs and create a single tarball file as output. The tarball file will be named jupyterProject.tar.gz
.
Now that we have the tarball, we can upload it, create a Docker image, and configure the Docker job.
Upload the tarball
To upload the prepared tarball, we have to navigate to the Docker Container section that looks like this:
-
Click on Change Docker File (Beta). Then select the tarball
jupyterProject.tar.gz
. -
Click on the
Save
button to start the docker image building process.
Adding the Docker job
Once the image is ready we can add the Docker Job by selecting Live job type as follows:
Live Demo
Now that we have done all the required steps, let’s navigate to any of our created task and preview it with following configurations:
Once we are in preview mode by clicking on the Launch Workspace
, we’ll get the following output:
In the above-given screenshot, it’s been reflected that we got the required Jupyter Notebook environment that we can utilize according to our needs. Moreover, the file named exampleFile.txt
is also there that we created in our earlier lessons using the editor option provided by the Workspace.
Let’s say we already included a file named
exampleNotebook.ipynb
using file editor or the upload option provided by Jupyter. How can we directly get into the file rather than the file tree as shown above?
The solution here is that we have to append the name of the file in the Workspace configurations Default URL as follows:
With this, when we’ll preview and launch the Workspace, we’ll get the desired output as follows: