Create and setup a Python development environment inside Docker in 5 minutes.
- Python 3.13
- Docker
Python packages used:
- fastapi
- hypercorn
git clone https://github.com/MikeCase/fastapi-docker.git
cd fastapi-docker
docker compose up -d --buildThe app will be available at http://127.0.0.1:8005 and should return {"key":"value"}.
| 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 |
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# Build the image
./build.sh
# Build and run
./up.sh- Check the container is running:
docker ps - View logs:
docker logs fastapi-docker-api-1 - Port already in use? Change the
8005:8005mapping indocker-compose.ymland theEXPOSEline inDockerfile