Multi-Container Environments (Docker Compose)
This page documents the technical specifications for using Docker Compose with AI Workbench projects.
- For conceptual background, see Docker Compose Environments.
- For step-by-step procedures, see Use Multi-Container Environments.
- For complete compose file examples, see Docker Compose Pattern Examples.
Requirements
- AI Workbench project with Docker Compose file in the repository.
- Basic understanding of Docker Compose syntax and concepts.
- For GPU services: NVIDIA GPU available on the host.
For more information about Docker Compose, see the Docker Compose documentation.
Compose File Specifications
The compose file is a YAML file that defines the services, networks, and volumes for a multi-container environment.
File Names and Locations
The compose file has restrictions in regards to the file name and location.
Valid File Names
AI Workbench recognizes the following file names:
- compose.yaml
- compose.yml
- docker-compose.yml
- docker-compose.yaml
Default Locations
AI Workbench expects the compose file to be in one of the following locations:
- Project root: /project/
- Deploy folder: /project/deploy/
Custom Location
You can specify a different location by editing the project specification file:
- Add the field environment:compose-file-path to .project/spec.yaml
- Set the value to the relative path to the compose file in the project
For more information about the project specification file, see AI Workbench Project Specification.
Service Profiles
Service profiles allow conditional service activation based on hardware or environment requirements.
For complete information about service profiles, see the Docker Compose profiles documentation.
Usage in AI Workbench:
- Select one or more profiles in Project Tab > Environment > Compose before starting.
- Services without a profile always run.
- Services with a profile only run when that profile is selected.
GPU Configuration in Compose
GPU configuration in compose specifies GPU allocation for services requiring GPU acceleration.
GPU Allocation by Count
You can specify GPU requests using the deploy.resources.reservations format with a count value.
AI Workbench manages GPU reservations and explicitly passes GPUs into each container, preventing conflicts between services.
Example with count:
Configuration Fields:
runtime: Should benvidiafor GPU accessdriver: Must benvidiacount: Number of GPUs to allocate to this service (Docker assigns available GPUs)capabilities: Must include[gpu]
GPU Allocation by Device ID
You can assign specific GPU devices to services using device_ids instead of count.
Example with device_ids:
Configuration Fields:
device_ids: List of specific GPU device IDs to assign- Device IDs correspond to GPU indices shown in
nvidia-smioutput - Multiple device IDs can be specified for multi-GPU services
When to use device_ids vs count:
- Use
countwhen you don’t care which specific GPUs are assigned - Use
device_idswhen you need precise GPU assignment across multiple services - Use
device_idsto prevent services from competing for the same GPU
Multi-GPU Configurations
Services requiring multiple GPUs can specify them using either count or device_ids.
Example with multiple GPUs:
Shared Memory for Multi-GPU:
- Multi-GPU services often require increased shared memory
- Set
shm_sizeto allocate shared memory (e.g.,20gb,16GB) - Required for inter-GPU communication in many AI workloads
GPU Allocation Conflicts
AI Workbench handles GPU reservation conflicts - if requested GPUs exceed available GPUs, the compose environment will fail to start with an error message.
Common conflict scenarios:
- Project container using GPUs that compose services request
- Multiple services requesting the same specific device_ids
- Total count across all services exceeds available GPUs
Resolution:
- Check GPU availability with
nvidia-smibefore starting services - Ensure the project container is not using GPUs needed by compose services
- Use device_ids to explicitly control GPU assignment across services
CPU and Memory Resources
Services can specify CPU and memory resource limits and reservations to prevent resource exhaustion.
Resource Limits
Resource limits define the maximum resources a service can consume.
Example:
Configuration Fields:
limits.cpus: Maximum CPU cores (e.g.,'2.0'for 2 cores,'0.5'for half a core)limits.memory: Maximum memory (e.g.,4G,512M)reservations.cpus: Minimum CPU cores reserved for the servicereservations.memory: Minimum memory reserved for the service
Best Practices:
- Set limits for inference services to prevent consuming all host resources
- Use reservations to guarantee minimum resources for critical services
- Important when running multiple AI services on a single host
Environment Variables and Secrets
You can use environment variables and secrets in your compose file to configure your services.
Environment Variables
Environment variables defined in your AI Workbench project are available in compose services through interpolation:
Special Environment Variables
PROXY_PREFIX: Automatically injected into services, contains the proxy routing path.NVWB_TRIM_PREFIX: Set totrueto enable proxy routing with prefix trimming.
Secrets
Secrets are used to store sensitive information in your compose file.
You can use AI Workbench secrets in your compose file in two ways:
-
Interpolation (as environment variables):
-
Compose secrets (as files):
When using compose secrets, the global secrets section must include the secret name with environment: "HOME". AI Workbench automatically replaces this value at runtime.
Networks
Networks enable service-to-service communication in multi-container environments.
Network Configuration
Services on the same network can reach each other using service names as hostnames.
Example:
Network Types:
bridge: Default network driver for standalone containers on a single host- Services on the same bridge network can communicate by service name
Service Discovery:
- A service named
backendis accessible at hostnamebackendfrom other services - Port numbers in inter-service communication refer to container ports, not host ports
- External port mappings (
ports) expose services to the host or AI Workbench proxy
Multiple Networks:
Services can connect to multiple networks for network segmentation and isolation.
Mounts and Volumes
You can use mounts and volumes in your compose file to share files and data between your services.
Volume Types
Docker Compose supports three volume types for persistent storage:
Named Volumes:
Managed by the container engine (Docker or Podman) and are useful for data that should persist but doesn’t need direct host access.
Bind Mounts:
Connect to specific host directories, useful for development or accessing existing data.
Tmpfs Mounts:
Store data in host memory, useful for temporary sensitive data.
Shared Volume
AI Workbench automatically creates a shared volume accessible to all containers. This shared volume has the following characteristics:
- Mount path: /nvwb-shared-volume
- Purpose: Enables file sharing between the project container and compose services.
- Permissions: If services run as different users, you may need to modify file permissions for shared access.
Bind Mounts
AI Workbench does not manage bind mount source paths for compose containers.
You must specify bind mount source paths directly in the compose file. These paths are relative to the project or absolute paths on the host.
Common Bind Mount Patterns:
External Volumes
External volumes are managed outside of Compose and must be created before starting services.
Create external volumes with docker volume create nim_cache before running compose.
Service Dependencies and Healthchecks
Service dependencies control startup order and ensure services are ready before dependent services start.
depends_on Configuration
The depends_on option specifies service dependencies.
Basic Dependency:
With Healthcheck Conditions:
Dependency Conditions:
service_started: Default, waits for service to start (not necessarily ready)service_healthy: Waits for service to pass healthcheckservice_completed_successfully: Waits for service to complete and exit successfully
Healthcheck Configuration
Healthchecks verify that a service is ready to accept requests.
Healthcheck Fields:
Configuration Options:
test: Command to run (returns 0 for healthy, 1 for unhealthy)interval: Time between healthcheck attemptstimeout: Maximum time to wait for healthcheck to completeretries: Number of consecutive failures before marking unhealthystart_period: Grace period before first healthcheck (useful for slow-starting services)
Common Healthcheck Patterns:
HTTP endpoint check:
Python script check:
Port check:
Best Practices:
- Define healthchecks for all critical services
- Use appropriate
start_periodfor services that take time to initialize - Set realistic
retriesandtimeoutvalues for AI services that may take time to respond - Healthchecks are essential for complex multi-service pipelines
Versioning
The compose file is versioned with the project. As long as the compose file is in a tracked folder in the project, Git will version it.
What is Versioned
Versioning occurs when the compose file is in a tracked folder in the project. As long as the compose file is in a tracked folder in the project, Git will version it.
What is NOT Versioned
The component images are not version when those images are used for services are not versioned. They are not versioned for the following reasons:
- Service container images are pulled from registries at runtime.
- Image versions are determined by tags in the compose file.
- Updating the compose file and committing changes does not version the actual container images.
Examples
Example 1: Simple Web Service
A basic compose file with a single web service that always runs:
Example 2: GPU-Enabled Service with Profile
A compose file with two services - one always runs, one requires GPU and uses a profile:
Example 3: Environment Variables and Secrets via Interpolation
A compose file using AI Workbench environment variables and secrets through interpolation:
Create the variable TEST_VAR and secret TEST_SECRET in your AI Workbench project before using this example.
Example 4: Compose Secrets as Files
A compose file using AI Workbench secrets through the Compose secrets mechanism:
Create the secret TEST_SECRET in your AI Workbench project before using this example.
Related Topics
- Docker Compose Environments - Understanding Docker Compose in AI Workbench
- Use Multi-Container Environments - How to create and run multi-container applications
- AI Workbench Project Specification - Project specification file reference
- GPU Configuration - GPU configuration for single containers
- Runtime Configuration (Environment Variables and Mounts) - Mount types and configuration
- Docker Compose Documentation - Official Compose documentation
- Compose File Specification - Complete Compose file reference