One File, Six Services: Running AI Agents With Docker Compose

Leader 1 6 55
calendar_today agoschedule2 min read

Most of us here already reach for Compose the moment a project grows past a single process, and agent work hits that point faster than almost anything else. What follows is the shape that keeps showing up once an agent stops being a script and starts being a system.

An Agent Is Never One Process

A working agent needs a runtime process, a model endpoint, a database for conversation history and agent state, and usually a vector store for retrieval. Add a queue once tasks run in the background, and something for traces once you need to know why a run went sideways. That is six services before anyone has written an interesting tool.

Running those by hand means remembering startup order, wiring hostnames and ports, and keeping six sets of environment variables in sync. Compose turns all of it into one declarative file with depends_on and health checks, so docker compose up produces the same stack on a laptop and on a server, and docker compose down leaves nothing behind.

The dependency isolation matters more here than in most stacks. Agent code pins specific versions of Python, PyTorch, and CUDA, and those pins conflict constantly. Two containers can run CUDA 12.4 and CUDA 11.8 side by side because each one carries its own dependency tree.

Three Patterns, Three Cost Profiles

The first pattern is API-backed. The agent container calls a hosted model, and the Compose file holds the runtime, a database, and whatever tools the agent needs. Minimal local resources, best available models, and a bill that scales linearly with usage.

The second runs a model server such as Ollama or vLLM in the same stack. The server holds the model in GPU memory and exposes an OpenAI compatible endpoint on the internal Docker network, so the agent reaches it by service name and configuration stays trivial. Per-call cost goes to zero and nothing leaves your infrastructure, but you own the GPU memory budget, and a large model can want anywhere from 20 to 80 GB of VRAM depending on parameter count and quantization.

The third is a hybrid that routes cheap high-volume calls to the local server and hard calls out to a frontier model. It is the pattern most teams land on eventually, and it is also the one that makes the routing logic worth testing.

The Parts That Bite Later

GPU access needs the device reservation in the Compose file and the container toolkit on the host, and it fails in a way that looks like a slow CPU run rather than an error. State needs named volumes, because a bind mount to a host path is the fastest way to lose a vector index during a rebuild. Service discovery is free inside the Compose network, which is exactly why it is worth being deliberate about which ports you publish to the host at all, since an unauthenticated model server on 0.0.0.0 is a real problem.

This guide to deploying AI agents with Docker Compose covers each of those in depth, along with the compose file anatomy and the move from a development stack to a production one.

Where Compose Stops Being The Answer

Compose is a single-host tool. When you need rolling updates across machines, autoscaling on queue depth, or real multi-tenancy, that is the Kubernetes conversation. Until then, a Compose file is the honest description of your architecture, and it is the artifact a new developer can read in two minutes and run in one command.

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

Infrastructure as Code: Deploying a Financial Ecosystem with Docker Compose

rvneto - May 1

From Dockerfile to Docker Hub: A Complete Beginner's Guide to Docker

madhavnaks - Jun 11

Leveraging Laravel with Docker for Streamlined Development

MasterCraft - Mar 9

From image to HTTPS endpoint in one step with ECS Express Mode

vishnu99 - Mar 19

Running Astro in a preview container

Steve Fenton - Jun 8
chevron_left
2.8k Points62 Badges
United Statest.co/5LlztlB5C5
62Posts
11Comments
16Connections
Our AI Apps are a self expanding AI SaaS ecosystem used to create the custom web application of your... Show more

Related Jobs

View all jobs →

Commenters (This Week)

1 comment
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!