Skip to content

Workshop on deploying a language detection app through Docker and FastAPI

License

Notifications You must be signed in to change notification settings

aihpi/mlops-docker

Repository files navigation

logo.png

Containerize your intelligence: A hands-on Workshop on Deploying AI models with Docker

Welcome to our workshop on deploying machine learning models using Docker, hosted by the AI Service Center in Berlin-Brandenburg. Visit our website for more details about our offerings!

Open this Repository on Gitpod

We can follow this workshop fully through Gitpod's VSCode, no need to install software locally, but we also provide the instructions for a local installation as an option.

Open in Gitpod

Local Installation Guide

This guide provides instructions for installing and setting up all the tools and environments you need to participate in the workshop. Familiarity with opening and using a terminal is required. Here's how you can start a terminal:

  • On Windows: Search for cmd or Command Prompt in the Start menu.
  • On Mac: Open the Terminal app from the Utilities folder.
  • On Linux: Use your distribution's default terminal.

Step 1: Install Git

  • Purpose of Git: Git is a version control system essential for managing code changes and collaboration.
  • How to Install: Download and install Git by following the instructions on Git Guides.
  • Verify Installation: In the terminal, run git --version. The output should display the Git version. You may need to restart your terminal before this command becomes accessible.

Step 2: Install Docker

Please install Docker before attending the workshop. Detailed instructions are provided below.

  • Purpose of Docker: Docker is key for creating and running containerized applications, ensuring consistency across environments.
  • How to Install: Follow the installation instructions based on your OS:
  • Verify Installation: In the terminal, run docker --version. The output should display the Docker version. Restarting your computer may be necessary before this command becomes accessible.

Step 3: Install an IDE

  • What's an IDE? An Integrated Development Environment (IDE) is a platform for coding, editing, and debugging your code. It also serves as a graphical user interface for Git.
  • Recommended IDEs:
  • Verify Installation: You can verify your installation by cloning a GitHub repository. Please refer to the following guides:

Troubleshooting and Support

If you encounter installation issues, consult the respective software's documentation or contact us at [email protected] for assistance.

What's Next?

Once you've installed Git, Docker, and an IDE, you're all set for our workshop. We're excited to introduce you to the world of MLOps and Docker!

Workshop Hands-On

Hands-On 1: Hello-World toy example

  1. (Optional) Look for the hello-world Docker image on Docker hub: https://hub.docker.com/
  2. Download the Docker image using the command: docker pull hello-world
  3. List your Docker images with the command: docker image ls
  4. Create a container using the hello-world image by running: docker run hello-world
  5. List your Docker containers using: docker ps --all
  6. Remove your Docker container with the command: docker rm [ID]
  7. Create a self-deleting container with the hello-world image using: docker run --rm hello-world

Hands-On 2: Model Training with Jupyter

  1. Open model/model_trainer.ipynb.
  2. Run all cells in the Jupyter notebook.
  3. Explain the code to your neighbour to make sure you understand it.
  4. Try changing the input text in the last cell. Do the answers make sense?

Hands-On 3: FastAPI

Task: Fill out the TODOs in the app/api.py file

  1. Read the FastAPI documentation: https://fastapi.tiangolo.com/tutorial/response-model/#response_model-parameter
  2. Read about the request body: https://fastapi.tiangolo.com/tutorial/body/
  3. You can test if your API is correctly defined py running python3 app/api.py and opening http://0.0.0.0:8000 in your browser.

Hands-On 4: Dockerfile

  1. Create a file with the name Dockerfile
  2. Find Python version 3.11 on Docker Hub and use it as a Base Image: FROM your-base-image:1.0
  3. Change the working directory inside of the container: WORKDIR /app
  4. Copy the requirements.txt file from the host file system into the docker container: COPY requirements.txt /to-container/
  5. Run a pip install for all the packages required: RUN pip install -r requirements.txt
  6. Copy the rest of the application into the container: COPY /from-host/ /to-container/
  7. Start the uvicorn server through the terminal command: CMD uvicorn app.location:api_name --host 0.0.0.0

Hands-On 5: Deploying the Container with Docker Compose

  1. Build and run the Docker container with Docker Compose: docker compose up --build
  2. Problem: Container shuts down when terminal closes. Solution: docker compose up -d
  3. Problem: Container doesn't restart when machine restarts. Solution: Add restart:always to the compose.yaml file.
  4. Problem: Application has errors and I need to see the logs. Solution: Use docker ps to get the container ID and then use docker logs [ID] to read the logs.
  5. Close the container using docker compose down

About

Workshop on deploying a language detection app through Docker and FastAPI

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •