Create and start the MiniConda container

Unfortunately, every time you will have to start the MiniConda container. However, the first time you need to retrieve the Jupyter API-key. When we login the the key we will see the content of the ~/Test/notebooks directory. The jupyter directtory called notebooks will be created for you.

content

Prerequisites

A PC or laptop running Ubuntu 22.04 with Git installed is required.

What you will do

Step 1: Create a directory ~/Test, where you create the file compose.yml.

Step 2: Create a directory ~/Test_Ed, where you clone Ed's repository.

Step 3: Get the Jupyter API-key

Step 4: Open a Notebook.

Step 5: Run conda to update packages.

compose.yml

version: "3.9" # Use the latest version of the Docker Compose file format

services:
  jupyter-notebook:
    image: continuumio/miniconda3
    ports:
      - "8888:8888"
    command: 
      - /bin/bash
      - "-c"
      - |
        conda install jupyter -y --quiet && \
        mkdir -p /opt/notebooks && \
        jupyter notebook \
          --notebook-dir=/opt/notebooks \
          --ip='*' \
          --port=8888 \
          --no-browser \
          --allow-root
    volumes:
      - ./notebooks:/opt/notebooks 
    tty: true
    stdin_open: true

Step 1: Create a directory ~/Test, where you create the file compose.yml.

Docker will use the comose.yml file to create the MiniConda container. You can access this containeer with your browser on port 8888.

StepAction
1Create ~/Test: mkdir ~/Test
2Goto the directory: cd ~/Test
3Create the file: nano compose.yml
4Go to the file compose.yml and click on the copy-symbol at the right-hand corner to copy the content to the clipboard.
5Paste the content into the file: Ctrl+Shift+V.
6Create the container: docker-compose -f compose.yml -d.
7Display the name of the container: docker container ls.

Step 2: Create a directory ~/Test_Ed, and clone Ed Donner's repo.

You will need a copy of Ed Donner's repository, with the notebook files. A notebook file can be uploaded to the MiniConda container.

StepAction
1Create the directory: mkdir ~/test_Ed.
2Goto the directory: cd ~/Test_Ed.
3Clone Ed's repository: git clone https://github.com/ed-donner/llm_engineering.git.

Step 3: Get the Jupyter API-key

You need the token the first time you login. To retrieve the token to copy the part after 'token=', with the command: jupyther server list.

StepAction
1Start a container, make use of autocompletion with the tab-button after typing test: docker start test_jupyter-notebook.
2Open a terminal and enter the container by typing: docker exec -it test_jupyter-notebook_1 bash.
3Type: jupyter server list. $\\$fig_3_3.png
4Copy (Ctrl+Shift+C) and save the token in a save place.
5You also have to add the dotenv module: pip3 install python-dotenv.
6And the OpenAI module: pip3 install OpenAI.
7Exit the container: Ctrl+D.

Step 4: Open a Notebook.

StepAction
1Start a container, make use of autocompletion with the tab-button as soon as you type test: docker start test_jupyter-notebook.
2Connect to the container using the browser: localhost:8888.
3Click on the Upload-button. $\\$fig_3_5
4Select the Test_Ed folder, and open it: Double click. $\\$fig_3_6
5Open the llm_engineering folder. $\\$fig_3_2
6Open the week1 folder. $\\$fig_3_4
7Select the day1.ipynb file. Load the file: double click, and save the file: Ctrl+S.
8Now you can work with the Notebook file.
10Load the other Notebooks of week1. When you look at ls ~/Test/notebooks you will see the uploaded files. Actually, the same as you see in the browser. $\\$fig_$\\$What you will see in the browser
Info

My experience is that I only have to enter the Jupter-key once! When I connect to the container I allways get an overview of the Notebooks I uploaded. Correction: I noticed that after a while you have retrieve a new API key to enter the container.

Step 5 - Run conda to update packages

A special file, called environment.yml, contains the packages you need for Ed Donner's course. Because Ed frequently updates his course, you will need to repeat these steps periodically.

StepAction
1Goto the /TestEd/ folder: `cd ~/TestEd`.
2Goto the llmengineering folder: `cd llmengineering`.
3Show the content of the file environment: cat environment.yml
4Highlight the content and copy it to the clipboard: Ctl+Shift+C
5Goto the /Test/notebooks folder: cd ~\Test\notebooks
6Create a file environment.yml: sudo touch environment.yml
7Start Nano with the file: sudo nano environment.yml
8Paste clipboard into the file: Ctrl+Shift+V
9Save the file: Ctrl+O
10Leave Nano: Ctrl+X
11Open the container: docker exec -it test_jupyter-notebook_1 bash
12Goto the /opt/notebooks folder: cd /opt/notebooks
13Display the files: ls $\\$fig 3.7
14Check whether the file environment.xml exists.
15Update the Anaconda environment: conda install environment.yml
16Activeer de omgeving: conda activate llms. (base) is replaced by (llms)
Important!

You should alway activate the environment with conda activate llms after you start the container!

Enter the container with: docker exec -it test_jupyter-notebook_1 bash, then type: conda activate llms.

Then, leave the container with: Ctrl+D.

Some Docker commands

CommandComment
docker container lslist al running (active) containers.
docker container ls -aList all the containers (also the not running ones). In the first column shows the id's of the containers.
docker container rm test_jupyter_notebook_1Delete a container. Use the Tab-key for auto-completion after typing test!
docker container rm ef6f974a579fDelete a container by its id.
docker image lsList all repositories (images).
docker exec -it <container name or id> /bin/bashEnter a container.

We are not finished yet. To work with ChatGPT you first have to put its API-key in a file named: .env.

Summary

The chapter describes the process of starting a MiniConda container, specifically for working with Jupyter notebooks. It begins by stating that users must start the MiniConda container each time they want to work, but highlights that the Jupyter API key needs to be retrieved only during the initial login. Upon logging in with the key, users will gain access to the contents of the ~/Test/notebooks directory.