Docker Compose Pattern Examples
This page provides complete, tested compose file examples for common multi-container patterns in AI Workbench.
- For compose file specifications, see Multi-Container Environments (Docker Compose).
- For step-by-step procedures, see Use Multi-Container Environments.
- For conceptual background, see Docker Compose Environments.
Pattern 1: NIM Model Selection with Profiles
Use Case
Run one of several NIM models based on available GPU resources.
Users select a model size that fits their hardware. Multiple models share the same port and interface. Profiles enable easy switching without maintaining separate compose files.
This pattern works well for:
- Development and testing with different model sizes
- Demos where users have varying hardware capabilities
- Projects where model selection happens at deployment time
Key Features
- Multiple services with identical interfaces
- Profile-based service selection
- Variable GPU requirements per model
- Shared network configuration
- Model cache volume management
Example Configuration
Compose file with three model variants:
Configuration Notes
GPU count varies by model size:
- 8B model: 1 GPU
- 70B model: 2 GPUs
- 405B model: 8 GPUs
All models use the same port (8000):
Only one model can run at a time. This is intentional for easy model switching.
Model cache mounted to /tmp:
Change source: /tmp to a dedicated directory for persistent caching.
Ensure the directory has write permissions.
NGC_API_KEY is required:
Set the NVIDIA_API_KEY secret in AI Workbench.
The compose file validates this variable is set before starting.
Profiles match model names:
Select the profile matching your desired model in the AI Workbench UI. Only the selected model’s service will start.
Pattern 2: Full RAG Pipeline with Multiple Services
Use Case
Run a complete RAG system with ingestion, retrieval, generation, and frontend services.
Each component runs in its own container with specific GPU assignments. Multiple profiles enable running different subsets of services. Services communicate over a shared network with healthcheck dependencies.
This pattern works well for:
- Production RAG applications
- End-to-end AI pipelines
- Applications requiring multiple specialized models
- Systems with document processing, vector search, and generation
Key Features
- Multiple GPU-accelerated services on different GPUs
- Profile-based deployment modes (local, ingest, rag, vectordb, guardrails)
- Service dependencies with healthchecks
- Persistent storage with volumes
- Web service integration with NVWB_TRIM_PREFIX
Example Configuration
Compose file excerpt showing key services:
Configuration Notes
Services are organized by profile:
local: GPU-accelerated inference services (NIMs)rag: RAG orchestration and frontendvectordb: Vector database and dependenciesingest: Document ingestion pipelineguardrails: Optional content safety services
GPU assignment uses device_ids:
device_ids: ['${LLM_MS_GPU_ID:-1}'] assigns a specific GPU.
Environment variables (LLM_MS_GPU_ID, EMBEDDING_MS_GPU_ID) control which GPU each service uses.
Default values provided after :- if variables are not set.
Services communicate by name:
APP_LLM_SERVERURL: "nim-llm:8000" connects to the nim-llm service.
All services share the nvidia-rag network.
Healthchecks ensure proper startup order:
Services with depends_on wait for dependencies to be healthy.
Healthchecks use HTTP endpoints or curl commands.
NVWB_TRIM_PREFIX enables proxy for frontend:
The rag-frontend service is accessible through AI Workbench’s proxy. Backend services do not need this variable.
Volumes provide persistent storage:
Model caches in /opt/nim/.cache persist between restarts.
Vector database and Minio data stored in ./volumes/.
Pattern 3: Custom Microservices with Build Contexts
Use Case
Build and run custom application services alongside supporting infrastructure.
Your own code runs in containers built from Dockerfiles. Services communicate through a shared network and message queues. Supporting services provide databases, caching, and observability.
This pattern works well for:
- Custom AI applications with multiple components
- Microservices architectures
- Applications requiring specialized build steps
- Integration with external APIs and services
Key Features
- Custom Dockerfiles with build contexts
- Service-to-service communication via networks
- Message queues and task systems (Celery, Redis)
- Observability with tracing (Jaeger)
- Persistent volumes for shared data
Example Configuration
Compose file with custom services:
Configuration Notes
Services use custom Dockerfiles:
build.context sets the build directory.
build.dockerfile specifies the Dockerfile path.
AI Workbench builds these images when starting compose.
Services communicate through service names:
PDF_SERVICE_URL=http://pdf-service:8003 references the pdf-service by name.
All services must be on the same network.
Redis provides message queue and caching:
Multiple services connect to the same Redis instance. Celery uses Redis as broker and result backend.
Volumes share data between services:
pdf_temp volume is shared between pdf-api and celery-worker.
Bind mounts (./models.json) inject configuration files.
Dependencies ensure startup order:
depends_on starts redis before services that need it.
Does not wait for services to be healthy unless healthchecks are defined.
Jaeger provides distributed tracing:
Services can send traces to Jaeger for observability. Jaeger UI accessible at http://localhost:16686.
Best Practices Across All Patterns
Use named networks for better isolation:
Create explicit networks instead of relying on the default network. Makes service communication explicit and easier to debug.
Define healthchecks for critical services:
Prevents dependent services from starting before dependencies are ready. Use HTTP endpoints or simple commands that verify service readiness.
Use environment variables for configuration:
Reference secrets and configuration through ${VARIABLE_NAME} syntax.
Set variables in AI Workbench or .env files.
Never hardcode sensitive values in compose files.
Pin image versions in production:
Use specific tags (image:1.2.3) instead of latest.
Ensures reproducible deployments across environments.
Use volumes for persistent data:
Model caches, databases, and application data should use volumes. Prevents data loss when containers restart.
Organize services with profiles:
Group related services into profiles for different deployment scenarios. Enables flexible deployments without maintaining multiple compose files.
Document GPU requirements clearly:
Comment GPU assignments and memory requirements. Helps users understand hardware requirements before deployment.
Use service names for inter-service communication:
Services on the same network can reach each other by service name. Avoid using localhost or IP addresses for service-to-service calls.
Related Topics
- Use Multi-Container Environments - How to manage compose environments
- Docker Compose Environments - Understanding Docker Compose in AI Workbench
- AI Workbench Project Specification - Project specification file reference
- Docker Compose Documentation - Official Compose reference
- NVIDIA NIM Documentation - NIM deployment guides