Jupyter Notebook for OCI Generative AI on the Cloud

Matt MulvaneyMatt Mulvaney
4 min read

This blog sets up Jupyter Notebook on an OCI computer machine using docker. It then shows you how to configure your credentials to call the OCI Generative AI service. It also describes configuration of SSL and custom domains to access your notebook.

You can use this blog for installing Jupyter Notebook locally on your laptop too.

Note: Chicago or Frankfurt regions only support Generative AI at time of writing.

Setup Environment

  1. Create a Compute Instance on Oracle Cloud

  2. Install Docker

HTTPS / SSL / Custom Domain Instructions

Only follow these instructions if you want HTTPS/SSL

  1. Obtain your Origin Certificate and Key from Cloudflare (or your Domain Registrar) e.g SSL/TLS > Origin Server > Create Certificate

  2. Create your key

     nano notebook.key
    

    paste in your key.

     nano notebook.crt
    

    Paste in the cert

  3. OPTIONAL: If you don't have a key, create a key pair...

     openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout notebook.key -out notebook.crt
    
  4. Start the container which will first download the image

     docker create -it --name jupyter -p 10000:8888 \
         -e GEN_CERT=no \
         quay.io/jupyter/scipy-notebook:latest \
         start-notebook.py \
         --ServerApp.keyfile=/etc/ssl/certs/notebook.key \
         --ServerApp.certfile=/etc/ssl/certs/notebook.crt
    
  5. Copy the keys to the container

      docker cp notebook.key jupyter:/etc/ssl/certs/notebook.key
      docker cp notebook.crt jupyter:/etc/ssl/certs/notebook.crt
    
  6. Star the jupyter container

     docker start jupyter
    
  7. Now go to your NGINX Proxy Manager Panel - Here is a guide if you've not set it up

  8. Create a Proxy host like this. I had to use the local IP address of the compute box for some reason as it wasn't resolving. Also, Websockets Support must be on.

  9. Then choose your Origin Certificate

HTTP Instructions

Only follow these instructions if you want HTTP not HTTPS

  1. Start the container which will first download the image

     docker run -d -it --name jupyter -p 10000:8888 quay.io/jupyter/scipy-notebook:latest
    

Access Jupyter

  1. Now the container is running, list the Logs.

     docker logs jupyter
    

    Gives you the URL including the token

     [I 2024-06-09 14:55:38.236 ServerApp] http://127.0.0.1:8888/lab?token=abc
    
  2. Open Ports 10000 using this guide e.g

     sudo firewall-cmd --permanent --zone=public --add-port=10000/tcp
     sudo firewall-cmd --reload
    

    Then add an Add Ingress Rule to the Default Security List also by following this guide

  3. Put the URL in the browser (without the token), but make sure to change the port from 8888 to 10000 and your IP (or use localhost)

    To fetch your IP type

     curl ipconfig.io
    

    and then format the URL like this

     http://19.19.19.19:10000/lab
    

    or like this

     http://localhost:10000/lab
    

    or if using SSL

     https://my-custom-domain/lab
    
  4. Paste the URL into your browser

  5. Paste in the token (from the logs) and set a new password

  6. You can now use your password to log in the future rather than the token.

  7. Click on Terminal

  8. Install OCI SDK

     pip install oci
    
  9. Create an .oci folder to hold the credentials

     mkdir ~/.oci
    
  10. Create a new PEM file in Nano (we wont edit it just yet)

    nano ~/.oci/oci_api_key.pem
    
  11. In OCI, Click Profile > My Profile

  12. Click API Keys > Add API Key > Download API Key

  13. Don't touch anything in OCI yet, Open the downloaded file in VSCode & copy it to Clipboard

  14. Back in Jupyter Console, paste it in to Nano and use CTRL+X to save and exit.

  15. Back in OCI press Add

  16. Don't touch anything in OCI yet, keep the window open

  17. Back in Jupyter Console, type

    nano ~/.oci/config
    
  18. Copy the info from OCI to clipboard

  19. Paste in to Nano

  20. Change the last line to

    key_file=~/.oci/oci_api_key.pem
    
  21. CTRL+X to save and exit nano

Testing

  1. Go to the OCI Generative Playground

  2. Type in a query and hit submit

     Give me 5 fun bullet point facts about Leeds United
    
  3. Click View Code > Python > Copy Code

  4. In Jupyter, click Python3 (ipykernal) icon

  5. Paste the code directly in

  6. Click the Run/Play Icon or shift-enter to run

  7. Enjoy

Next Steps

Dracula Theme

Of course you need Dracula Theme.

  1. Install Dracula Theme in Terminal

     pip install JLDracula
    
  2. Refresh the Browser

  3. Settings > Themes > JLDracula

ENJOY!

Whats the picture? It's Adel Dam Nature Reserve, Leeds. I tried to spot a real Kingfisher, but I failed.

0
Subscribe to my newsletter

Read articles from Matt Mulvaney directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Matt Mulvaney
Matt Mulvaney

With around 20 years on the job, Matt is one of the most experienced software developers at Pretius. He likes meeting new people, traveling to conferences, and working on different projects. He’s also a big sports fan (regularly watches Leeds United, Formula 1, and boxing), and not just as a spectator – he often starts his days on a mountain bike, to tune his mind.