A simple todo list API that runs in Docker containers.
Create a file named .env in the TodoList-API folder with these contents:
DB_USER=myuser
DB_PASSWORD=mypassword
DB_NAME=tododb
DB_HOST=db
DB_PORT=5432Note: Change myuser and mypassword to whatever you want.
Open docker-compose.yml and uncomment the web service section (remove the # symbols from lines 22-35).
Open a terminal in the TodoList-API folder and run:
docker-compose up --buildThis will:
- Build the Docker image for the FastAPI application
- Start the PostgreSQL database container
- Start the FastAPI web application container
- Create the necessary database tables automatically
Once it's running, open your browser and go to:
- API Documentation: http://localhost:8000/docs
- API: http://localhost:8000
Press Ctrl+C in the terminal, then run:
docker-compose down- The database data is saved in a Docker volume, so your data persists even if you stop the containers
- To completely reset everything (including database data), run:
docker-compose down -v - If you only want to run the database, you can leave the web service commented out in
docker-compose.yml