[INFRA-AI-02] FastAPI Gateway Containerization and Local Ollama Inference Orchestration
Infrastructure / MLOps
NoteTask Brief
- Repository / Component:
ai_receipt_vision_gateway. - Stack: Docker, Docker Compose, Ollama API.
- Task Type: DevOps / Infra.
- Status: Ready for Implementation
Task Description
It is necessary to package the developed Python gateway into a Docker container and configure the joint launch of the web service and the local Ollama environment via Docker Compose for running inference on the CPU.
Step-by-Step Instructions
- Writing the Dockerfile for the Gateway: Prepare a build file for the FastAPI application based on a lightweight
python:3.10-slimimage. Ensure the installation offastapi,pydantic,requests, anduvicorndependencies viapip install. Expose port11435. - Designing the Docker Compose Manifest: Define two linked services:
ai-gateway— the container running FastAPI. Map port11435:11435and pass the environment variableOLLAMA_HOST=http://ollama-core:11434.ollama-core— the officialollama/ollamaimage. Map port11434:11434. Attach a Docker Volume for the/root/.ollamadirectory so that downloaded models are not erased upon restart.
- Automating Model Downloads (Build Modeling): Write a companion bash script (or entrypoint) that, after the
ollama-corecontainer starts, automatically executes a command inside the container:ollama run llama3.2-vision:11bto pre-download the model weights to the disk.