This project provides a template for deploying a FastAPI application using Docker. It includes configurations for building and running the application in a containerized environment.
- FastAPI Application: A simple FastAPI app with a basic endpoint.
- Docker Integration: Dockerfile and docker-compose configurations for containerization.
- Environment Variables: Support for environment variables to configure the application.
- Docker installed on your system.
- Docker Compose installed.
-
Clone the Repository:
git clone https://github.com/awaismughal2020/fastapi-docker.git cd fastapi-docker -
Build and Run the Application:
Use Docker Compose to build and run the application:
docker-compose up --build
This command builds the Docker image and starts the FastAPI application.
-
Access the Application:
Once the container is running, access the application at
http://localhost:8000. -
Interactive API Documentation:
FastAPI provides interactive API documentation using Swagger UI. Access it at
http://localhost:8000/docs.
fastapi-docker/
├── app/
│ ├── main.py
│ └── ...
├── Dockerfile
├── docker-compose.yml
└── README.md
app/: Contains the FastAPI application code.Dockerfile: Defines the Docker image for the FastAPI application.docker-compose.yml: Configuration for Docker Compose to run the application.
The application can be configured using environment variables. Update the .env file or set them directly in your environment.