Navigate to the location where you want to create your project directory.
Create a new directory for your project:
mkdirfastapi-dockercdfastapi-dockercode.
This will open a new VScode window
Open the terminal in VSCode (Ctrl + `).
Create the src Directory:
Inside your project directory, create a src directory:
mkdirsrc
Create main.py Inside src:
Navigate into the src directory and create the main.py file:
Add Code to main.py:
Open main.py in VSCode and add the following code:
Create requirements.txt:
Go back to the root of your project directory and create a requirements.txt file:
Add the following dependencies to requirements.txt:
Create the Dockerfile:
In the root of your project directory, create a Dockerfile: Dockerfile
Add the following content to the Dockerfile:
Automate Docker creation using YML
Create docker-compose.yml file in parent directory
Run docker compose
Access the Application
Open your web browser and go to http://localhost:80. Any changes you make to main.py in the src directory will be automatically reflected in the running container.