This repository contains the materials for the Introduction to Containerisation Workshop by the Google Developers Student Club (GDSC) Delft . In this workshop, we will cover the basics of containerisation and demonstrate how containerize the REST API using Docker.
Before attending this workshop, you should have some basic understanding of Python and web development. You should also have Docker and Python (preferably version 3.9 and higher) installed on your machine. If you need help installing Docker, you can refer to the official documentation.
To get started, clone this repository to your local machine if you have git
installed :
# HTTPS
$ git clone https://github.com/GDSC-Delft-Dev/intro-to-containerisation-workshop.git
# SSH
$ git clone [email protected]:GDSC-Delft-Dev/intro-to-containerisation-workshop.git
Otherwise, you can simply download the repository:
In this workshop, we will use a REST API built Python
and FastAPI. To get started, navigate to the api
directory:
# Change directory to api
$ cd api
Before we can run the application, we need to install the necessary dependencies. It is highly recommended to create a virtual environment. To do this, we can use pip
:
# install all dependencies from requirements.txt
$ pip install -r requirements.txt
Creating a virtual environment in Python is a recommended practice to isolate dependencies for different projects. By isolating dependencies, you can avoid conflicts between packages and ensure that your projects have all the necessary libraries installed. Here's a step-by-step guide to creating a virtual environment in Python:
- Open a terminal window and navigate to the directory where you want to create the virtual environment.
- Type the following command to create a new virtual environment:
# Creates a myenv virtual environment
$ python -m venv myenv
- To activate the virtual environment, run the following command:
# Activate myenv on linux/Macos
$ source myenv/bin/activate
# Activate myenv on Windows
$ myenv\Scripts\activate
Once the virtual environment is activated, you will see the name of the environment in the command prompt.
# Linux
(venv) $
# Windows PowerShell
(venv) PS>
- Now you can install the required packages for your project using
pip
. - To exit the virtual environment, run the following command:
deactivate
This will deactivate the virtual environment and return you to the original shell.
Once the dependencies are installed, we can run the application using the following command:
# Run application
$ python main.py
This will start a local server that listens for incoming requests. You can test the application by sending requests to http://localhost:5000
through your web browser, curl
, Swagger documentation site at http://localhost:5000/docs
(Highly recommended) or client tools like:
Left as and exercise for the reader 😉.
Left as and exercise for the reader 😉.
Congratulations! You have successfully containerised a Python REST API using using Docker. We hope this workshop has given you a good introduction to containerisation and its benefits. If you have any questions or feedback, please don't hesitate to reach out.