This project is a FastAPI application with a PostgreSQL database, running entirely in Docker.
- Docker
- Docker Compose
- Optional:
psqlclient (if you want to connect from host machine)
- Clone the repository:
git clone https://github.com/PR202111/Apis.git
cd Apis- Build and start the containers:
docker-compose up --buildThis will start:
api-api(FastAPI server)api-db(PostgreSQL database)
Once the containers are running:
- FastAPI server: http://localhost:8000
- It will automatically reload on code changes.
You can stop the containers with:
docker-compose downdocker exec -it api-api bash
psql -h api-db -U postgres -d mydatabasepsql -h localhost -U postgres -d mydatabaseTables:
\dt;Sample query:
SELECT * FROM users;- Containers communicate using Docker network, using service names (like
api-db) as hostnames. - Port mapping (
5432:5432) is only needed if you want to access Postgres from your host machine. - Database initialization is handled automatically on first startup.
.
├── app/ # FastAPI application code
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
└── README.md