Project Services
import { Aside } from ‘@astrojs/starlight/components’;
cspace instances run in Docker Compose stacks. You can extend the stack with project-specific services — databases, caches, message queues, or any other container your project needs — by providing an additional Docker Compose file.
Adding services
Section titled “Adding services”1. Create a Docker Compose file
Section titled “1. Create a Docker Compose file”Place a docker-compose.yml in the .cspace/ directory at your project root:
services: # Extend the devcontainer with project-specific env vars devcontainer: environment: - DATABASE_URL=postgresql://dev:dev@postgres:5432/myapp
postgres: image: postgres:16 container_name: ${CSPACE_PREFIX}.${COMPOSE_PROJECT_NAME}.postgres environment: POSTGRES_DB: myapp POSTGRES_USER: dev POSTGRES_PASSWORD: dev volumes: - postgres-data:/var/lib/postgresql/data networks: - default
volumes: postgres-data:2. Reference it in .cspace.json
Section titled “2. Reference it in .cspace.json”{ "services": ".cspace/docker-compose.yml"}How it works
Section titled “How it works”When cspace up launches an instance, it composes multiple Docker Compose files together:
- Core compose — the built-in devcontainer definition
- Shared services — browser sidecars (Playwright, Chromium CDP)
- Project services — your
.cspace/docker-compose.yml(if configured)
Docker Compose merges these files, so your services file can both add new services and extend the existing devcontainer service with additional environment variables, volumes, or other settings.
Compose interpolation variables
Section titled “Compose interpolation variables”Use these Docker Compose interpolation variables to keep container names unique across instances:
| Variable | Description | Example value |
|---|---|---|
${CSPACE_PREFIX} | The project’s short prefix from config | mp |
${COMPOSE_PROJECT_NAME} | The full compose project name (prefix + instance name) | mp-mars |
Post-setup hook
Section titled “Post-setup hook”For initialization that needs to run after the container is created — such as database migrations, seed data, or one-time setup — use a post-setup script.
1. Create the script
Section titled “1. Create the script”#!/bin/bash# Example: set up a databaseset -euo pipefail
if [ -f /workspace/.cspace-db-done ]; then exit 0; fi
echo "Running database migrations..."cd /workspace && npm run migrate
touch /workspace/.cspace-db-done2. Reference it in .cspace.json
Section titled “2. Reference it in .cspace.json”{ "post_setup": ".cspace/post-setup.sh"}Putting it together
Section titled “Putting it together”To use both services and a post-setup hook, reference both in your .cspace.json:
{ "services": ".cspace/docker-compose.yml", "post_setup": ".cspace/post-setup.sh"}With the Docker Compose file and post-setup script from the examples above, each cspace instance gets its own Postgres container with its own data volume, so agents working in parallel never collide.
See Configuration Reference for all available config keys.