In this second post in my CloudFoundryFun series, I show you how to leverage Cloud Foundry to forge a new learning environment.
Learning with Jupyter Notebook
The rising popularity is also reflected by the number of .ipynb files (interactive python notebook – the file format of Jupyter Notebooks) on GitHub.
The rising popularity of Python Notebook on Github (Source)
Notebooks are the core of each Jupyter project and the origin of its simplicity. The code contained in them can be partitioned in small code snippets. The special feature is that those snippets can be enriched with explanations written in Markdown, a lightweight markup language. Beginners can execute the pre-defined snippets section by section. Each section is self-explanatory and thus, generates a unique learning environment.
An example of a Jupyter notebook with explanations and code next to each other
In this post we will run Jupyter Notebooks ON Cloud Foundry, thereby our notebooks will have access to Cloud Foundry services. This way, we can learn how to use Cloud Foundry services using Jupyter Notebook, running on Cloud Foundry.
Bundling the Learning Environment
It might be worth bundling the Notebook app with your training content like notebooks and possibly required datasets. The bundling can be done using with a new Docker image. This Dockerfile shows how new content can be added to an existing image:
FROM jupyter/minimal-notebook RUN rm -d work RUN mkdir Lesson_1 COPY Lesson_1 ./Lesson_1
Publishing the Image
- Login via the command line
- Build the image from the Dockerfile
docker image build -t "cloudfoundryfun2" .
- Read the ID of your image
- Tag the newly created image
docker tag <Image ID> <Dockerhub User>/cloudfoundryfun2:latest
- Publish the image to Dockerhub
docker push <Dockerhub User>/cloudfoundryfun2:latest
Note: You can skip this step and use the minimal-notebook if you don’t want to add your own data to the image.
Combine the image with your Cloud Foundry Services
This docker container will be bound to an SAP Leonardo Machine Learning Foundation service and an HDI container.
Build the MTAR archive with the cloud build tool.
The structure of our bundle
Deploying the Notebook
- Sign up for an SAP Cloud Platform account
- Enable Cloud Foundry
- Install the Cloud Foundry CLI
- Add the multi-apps plugin to the CLI
- Use your MTAR
- Deploy the archive
cf deploy jupyter_0.0.1.mtar
This command outputs the URL of the running app.
- Access the Notebook
You’ll notice that you need a token to access the notebook. You can find it in the logs of your application.
- Read the logs
cf logs juypter-notebook –recent
Copy and paste the token into the corresponding field.
- Login to service
Open the notebook in the folder “Lesson_1” (if you added data to your own docker image)
- Have fun learning!
Disclaimer: I recommend using Jupyter Notebooks on Cloud Foundry only for educational purposes. The application itself runs on hardware which wasn’t designed for compute intense tasks (as machine learning is one).
In this edition you have learned:
- What Jupyter Notebooks are and where they come from
- How Docker images can be enriched with additional files
- How to publish your own Docker images to Dockerhub
- How to deploy Docker images along with cloud services to SAP Cloud Platform Cloud Foundry
- How to read the log files of your Cloud Foundry apps
Would you like to learn more about the detailed steps (with actual training content) in a tutorial in our Developer Center? Let me know in the comments!
About this series
|This was the second blog post of my monthly new series #CloudFoundryFun. The name already says all there is to it, this series won’t be about building enterprise apps on Cloud Foundry. I think there are already plenty of great posts about those aspects out there. This series rather thinks outside the box and demonstrates unconventional Cloud Foundry use-cases. And sometimes it might be pure entertainment 🙃.|