Local Testing with Docker
In this part, we will explain how to run the backend (FastAPI) and Streamlit chat UI together using Docker Compose for quick local testing.
Prerequisites
- Install Docker (Docker Desktop for Windows/macOS, or Docker Engine for Linux).
- (Optional) Create a
.envfile at the project root so environment variables are auto-loaded:
IONOS_API_KEY=your_ionos_key_here
TAVILY_API_KEY=your_tavily_key_hereOn PowerShell you can also export them temporarily:
$env:IONOS_API_KEY = "your_ionos_key_here"
$env:TAVILY_API_KEY = "your_tavily_key_here"Start Services
From the repository root (IONOS-simple-chatbot/):
docker compose up --buildWhat happens:
- Builds
backend/→ imagebackend:latestexposing FastAPI at http://localhost:8000 - Builds
frontends/streamlit-starter/→ imagefrontend:latestserving UI at http://localhost:8501
Verify
- Open http://localhost:8000/docs for the FastAPI Swagger UI
- Open http://localhost:8501 for the Streamlit chat interface
Stopping & Cleanup
Press Ctrl+C to stop. To also remove containers, network, and anonymous volumes:
docker compose down -vRebuild After Changes
If Python dependencies changed (e.g., edited requirements.txt):
docker compose build --no-cache backend-service
docker compose upOnly code changes? Usually docker compose up --build is enough.
Troubleshooting
| Issue | Cause | Fix |
|---|---|---|
| Port already in use | Another process on 8000/8501 | Edit ports: mapping in compose file |
| 401 / tool errors | Missing API keys | Ensure env vars set (docker exec -it <container> env) |
| Changes not visible | Cached image layer | Use --build or build --no-cache |
| Slow first start | Dependency install | Subsequent runs are faster due to layer caching |