Skip to content

Docker

The application ships with a production-ready Dockerfile.


Dockerfile

Dockerfile
FROM python:3.10-slim

WORKDIR /app

# Install build dependencies required by chromadb
RUN apt-get update && apt-get install -y build-essential curl && rm -rf /var/lib/apt/lists/*

# Install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# Copy application source and data files
COPY . .

EXPOSE 8080

CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8080"]

Key Design Decisions

Decision Reason
python:3.10-slim Minimal base image; reduces attack surface and image size
build-essential Required by chromadb's native C extensions on Linux
--no-cache-dir Keeps the layer size small
Port 8080 Fly.io's expected internal port
COPY . . Bakes dbn-poc-database.db and chroma.sqlite3 into the image

.dockerignore

The following files are excluded from the Docker build context:

.dockerignore
__pycache__
*.pyc
.env
.git
.gitignore
*.ipynb
data/

Never ship your .env file

The .dockerignore ensures that .env (which may contain your API keys) is never baked into the image.


Building Locally

docker build -t dbn-analytics-poc .

Running Locally

docker run -p 8080:8080 \
  -e OPENAI_API_KEY="sk-..." \
  dbn-analytics-poc

Then visit http://localhost:8080/docs.


Image Size Optimisation Tips

  • Consider using a multi-stage build to separate the build environment from the runtime.
  • If the SQLite and ChromaDB databases grow large, consider mounting them as a Fly.io Volume instead.