This project is a simple example of how to use Fastapi with Docker.
docker build -t fastapi .
docker run --env-file .env -d --name fastapi_container -p 8002:8080 fastapi
curl http://localhost:8002
Bash output:
{"message":"Hello World"}
Go to url: http://localhost:8002
docker stop fastapi
docker rm fastapi
docker rmi fastapi
Go to url: http://localhost:8002/docs
- Create a virtual environment
python3 -m venv venv
- Activate the virtual environment in linux or mac
source venv/bin/activate
- Activate the virtual environment in windows
venv\Scripts\activate
- Install the dependencies
pip install -r requirements.txt
- Run the application
uvicorn main:app --reload