Simple task management API built with FastAPI, PostgreSQL, Docker and Docker Compose.
This project is a basic backend API created to practice real-world backend concepts such as:
- FastAPI application structure
- PostgreSQL integration
- Database connections with psycopg2
- Docker containerization
- Multi-container orchestration with Docker Compose
The API communicates with a PostgreSQL database running inside a separate container.
The database is initialized automatically using init.sql when the PostgreSQL container starts for the first time.
- Python 3.12
- FastAPI
- PostgreSQL
- psycopg2
- Docker
- Docker Compose
task-manager-api/
│
├── app/
│ ├── database.py
│ └── main.py
│
├── .dockerignore
├── .gitignore
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── README.mdThe application uses two containers:
Container name:
api-containerResponsibilities:
- Runs FastAPI
- Handles routes/endpoints
- Connects to PostgreSQL
Container name:
postgres-containerResponsibilities:
- Stores application data
- Provides database access
Current database settings:
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=task_manager_db
Connection URL used by the API:
postgresql://postgres:postgres@postgres:5432/task_manager_db
Important:
Inside Docker Compose:
postgres
is the service name used as the host.
Do not use:
localhost
because containers communicate internally through service names.
Build and start all services:
docker compose up --buildStop containers:
docker compose downCheck running containers:
docker psCreate virtual environment:
python3 -m venv venvActivate environment:
Linux:
source venv/bin/activateInstall dependencies:
pip install -r requirements.txtRun API:
uvicorn app.main:app --reloadGET /db-testExample response:
{
"message": "Database connected successfully"
}GET /tasksExample response:
{
"results": [
[1, "Study Docker"],
[2, "Learn PostgreSQL"]
]
}View logs:
docker logs api-containerdocker logs postgres-containerRebuild containers:
docker compose up --buildStop containers:
docker compose downThis project was created to practice:
- Docker fundamentals
- Docker Compose
- FastAPI
- PostgreSQL
- Backend architecture basics
- Container communication