This project sets up a simple FastAPI application (with some vulnerabilites) within a Docker container. It uses the official Python runtime and includes all necessary configurations to deploy a FastAPI app with Docker. The container will expose the app on port 80 and automatically run the FastAPI app on startup.
- Docker
- Python 3.12+
- FastAPI
- Uvicorn
- Dockerized FastAPI application: A containerized setup for easy deployment.
- Python 3.12.5 runtime: Uses the latest stable Python version as a base.
- Efficient package installation: Installs required dependencies via
requirements.txt
.
gcp-python-fastapi/
├── Dockerfile
├── requirements.txt
├── main.py # FastAPI app entry point
└── ...
- Dockerfile: Configures the Docker container for the FastAPI app.
- requirements.txt: Specifies the required Python dependencies for the application.
- main.py: The entry point for the FastAPI application (Make sure to include this file in the project structure).
If you haven't cloned the project yet, use the following command:
git clone https://github.com/your-username/awesome-fastapi.git
cd awesome-fastapi
To build the Docker image, run the following command in the root of the project directory:
docker build -t awesome-fastapi .
After the image is built, run the container:
docker run -d -p 80:80 awesome-fastapi
This command will run the FastAPI app on port 80 of your localhost.
Once the container is running, you can access the FastAPI application by navigating to:
http://localhost:80
The project uses the following Python packages, which are listed in the requirements.txt
file:
fastapi
: The core framework for building the API.uvicorn
: ASGI server to run the FastAPI application.
To install dependencies locally, use the following:
pip install -r requirements.txt
- This setup assumes that your FastAPI app’s entry point is
main.py
, and the FastAPI application instance is namedapp
. If your app is structured differently, you may need to modify theCMD
directive in the Dockerfile accordingly. - The container will expose the application on port 80. If you want to use a different port, adjust the
EXPOSE
andCMD
directives in the Dockerfile.