Skip to content

Latest commit

 

History

History
56 lines (41 loc) · 1.44 KB

File metadata and controls

56 lines (41 loc) · 1.44 KB

Purpose

Create and setup a Python development environment inside Docker in 5 minutes.

What you need

  • Python 3.13
  • Docker

Python packages used:

  • fastapi
  • hypercorn

Quick start

git clone https://github.com/MikeCase/fastapi-docker.git
cd fastapi-docker
docker compose up -d --build

The app will be available at http://127.0.0.1:8005 and should return {"key":"value"}.

Files

File Purpose
main.py FastAPI application with a single / route
Dockerfile Builds a container with Python 3.13-slim, installs deps, serves with Hypercorn
docker-compose.yml Orchestrates the build and run with a bind mount for live code reload
requirements.txt Python dependencies
.dockerignore Excludes .venv, __pycache__, .git, .env from the image

Development workflow

Edit code locally — the bind mount syncs changes to the container instantly. Hypercorn's --reload flag picks them up automatically. Only rebuild when you add new dependencies:

pip install some-package
pip freeze > requirements.txt
docker compose up -d --build

Helper scripts

# Build the image
./build.sh

# Build and run
./up.sh

Troubleshooting

  • Check the container is running: docker ps
  • View logs: docker logs fastapi-docker-api-1
  • Port already in use? Change the 8005:8005 mapping in docker-compose.yml and the EXPOSE line in Dockerfile