A practical approach to organizing AI applications with Docker, separating APIs, workers, model inference, storage, and observability.
An AI application rarely consists of just an API and an LLM integration. Once you introduce document ingestion, vector search, background workers, local models, and observability, infrastructure becomes part of the application architecture.
Putting everything inside a single Docker container might work for a prototype, but it quickly becomes difficult to maintain, monitor, and scale.
The Docker layout, networks, and Compose configuration below are a proposed architecture for an Enterprise RAG system. The observability section also describes an implemented local baseline from the project's architecture documentation; it does not imply that the proposed Docker deployment has been implemented.
Let's take an Enterprise RAG application as an example.
| Service | Responsibility | | --------------------- | ------------------------------------ | | FastAPI | HTTP API and request processing | | Index worker | Document ingestion and indexing | | PostgreSQL + pgvector | Persistent storage and vector search | | vLLM | Local model inference | | Arize Phoenix | AI tracing | | Prometheus | Operational metrics | | Grafana | Monitoring dashboards | | Alertmanager | Operational alerts |
Each service has a different lifecycle, resource profile, and operational responsibility.
The API handles incoming requests. The indexing worker processes background jobs. The database maintains persistent state. The model server consumes computational resources independently of the application. These are natural container boundaries.
flowchart LR
Client[Client] --> API[FastAPI]
API --> DB[(PostgreSQL and pgvector)]
API --> Model[vLLM model server]
Worker[Index worker] --> DB
Worker --> Model
API -. operational traces .-> Phoenix[Arize Phoenix]
Worker -. operational traces .-> Phoenix
API -. metrics .-> Prometheus[Prometheus]
Worker -. metrics .-> Prometheus
Prometheus --> Grafana[Grafana]
Prometheus --> Alertmanager[Alertmanager]
The diagram shows logical relationships, not an exact network or deployment configuration. Actual connections depend on the implementation and metric collection setup.
I prefer organizing the infrastructure separately from the application logic.
enterprise-ai/
├── src/
│ ├── api/
│ ├── retrieval/
│ ├── ingestion/
│ ├── security/
│ ├── observability/
│ └── workers/
├── tests/
├── scripts/
├── infrastructure/
│ ├── docker/
│ │ └── Dockerfile
│ ├── prometheus/
│ ├── grafana/
│ └── alertmanager/
├── compose.yaml
├── compose.dev.yaml
├── compose.prod.yaml
├── .env.example
└── pyproject.toml
The application remains independent of its deployment configuration. Development and production environments share the same base Compose configuration, with environment-specific overrides where necessary.
Separating containers does not necessarily mean building a different Docker image for every service. The API and indexing worker can use the same application image while running different entry points.
services:
api:
image: enterprise-ai:local
build:
context: .
dockerfile: infrastructure/docker/Dockerfile
command: uvicorn enterprise_ai.main:app --host 0.0.0.0
index-worker:
image: enterprise-ai:local
command: python scripts/run_index_worker.py --limit 20
postgres:
image: pgvector/pgvector:pg16
volumes:
- postgres_data:/var/lib/postgresql/data
volumes:
postgres_data:
This is an illustrative excerpt, not a complete runnable or production configuration: database credentials, application configuration, connectivity, readiness, and other deployment details are omitted. Build the shared image before starting the worker.
This approach keeps application dependencies consistent while allowing each process to be deployed, restarted, and scaled independently.
The worker command in this example processes a bounded batch. A continuous production worker would require an appropriate scheduling or job-consumption mechanism.
Not every container needs to be accessible from outside the Docker environment. PostgreSQL, the indexing worker, and the model server should communicate through private Docker networks whenever possible. Only services that require external access should expose host ports.
For an Enterprise AI system, I would separate the infrastructure into three logical networks:
Network separation reduces unnecessary connectivity between services. It does not replace authentication, authorization, or outbound traffic controls. Services that need to communicate across these boundaries would need appropriate network membership and access controls.
AI systems introduce operational problems that traditional HTTP monitoring alone cannot explain. A successful HTTP response does not necessarily mean that retrieval was successful, that the answer was grounded, or that sufficient evidence was available.
The project's observability documentation describes an implemented local baseline with three layers:
This is an implemented observability baseline, while the Docker layout and service arrangement in this article are proposals. Production notification ownership, escalation, and telemetry access and retention policies still need to be established.
In an enterprise environment, telemetry itself can become a data leakage channel. User questions, retrieved documents, PII, authentication tokens, and tenant identifiers should not automatically become part of a trace. Instead, the application should explicitly define which operational fields are allowed to leave the execution context.
For example:
{
"event": "answer.completed",
"latency_ms": 742.04,
"evidence_count": 1,
"citation_count": 1,
"abstained": false,
"reason_code": "grounded_answer"
}
This provides useful diagnostic information without exposing the actual question or retrieved content. Telemetry supports operational diagnosis; it is not a complete audit trail.
Containers should be replaceable. Application data should not be.
PostgreSQL data, downloaded model weights, and persistent observability storage should have explicitly managed volumes. Application containers should remain stateless wherever possible.
This makes deployments more predictable and allows application services to be restarted or replaced without losing persistent data. Volumes, however, are not backups. Backup and recovery procedures must be managed separately.
One advantage of separating services early is that infrastructure can evolve without requiring a complete application redesign.
If document ingestion becomes a bottleneck, additional workers can be introduced, provided that job claiming and processing are concurrency-safe. If API traffic increases, multiple API instances can run behind a reverse proxy. If local model inference becomes resource-intensive, the model server can be moved to a dedicated GPU machine.
The application architecture remains largely unchanged.
Docker Compose is a reasonable starting point for a single-host deployment. Multi-host orchestration can be introduced later when availability, workload distribution, or operational requirements justify it.
Docker is not just a way to package an AI application. It is also an opportunity to make architectural boundaries explicit.
I would rather start with a small number of well-defined services than introduce Kubernetes, distributed queues, and complex orchestration before there is an actual need for them. The important part is designing the system so that individual components can evolve independently.
Start simple, but make the boundaries clear.