docs/examples/ci-cd/compose-tests.mdx
Run Docker Compose inside a microVM when a test needs several containers. The inner daemon gets its own disk and never receives the host's /var/run/docker.sock.
This example assumes the current directory contains compose.yaml and a test service named test.
<Tooltip tip="On microsandbox cloud, create a directory-backed Docker volume first and omit disk-kind, size, and replace-on-create options from this command."><span className="msb-badge-limited">Limited on cloud <Icon icon="circle-info" size={11} /></span></Tooltip>
<CodeGroup> ```sh macOS & Linux msb run -d --name compose-ci --replace \ --memory 2G --root-disk 4G --max-duration 10m \ --mount-named compose-ci-cache:/var/lib/docker:kind=disk,size=6G \ --copy-dir .:/workspace --workdir /workspace \ docker:27.5.1-dind ```msb run -d --name compose-ci --replace `
--memory 2G --root-disk 4G --max-duration 10m `
--mount-named compose-ci-cache:/var/lib/docker:kind=disk,size=6G `
--copy-dir .:/workspace --workdir /workspace `
docker:27.5.1-dind
The official dind image starts dockerd. Wait for it before sending Compose commands:
for ($attempt = 1; $attempt -le 60; $attempt++) {
msb exec compose-ci -- docker info *> $null
if ($LASTEXITCODE -eq 0) { break }
Start-Sleep -Seconds 1
}
msb exec compose-ci -- docker info *> $null
if ($LASTEXITCODE -ne 0) { throw 'Docker did not become ready' }
msb exec --timeout 5m --workdir /workspace compose-ci -- `
docker compose up --build `
--abort-on-container-exit `
--exit-code-from test
Replace test with the service whose exit code should decide the CI result. msb exec returns that code to the host.
Stop the Compose stack inside the sandbox:
msb exec --workdir /workspace compose-ci -- docker compose down --volumes
Remove the sandbox:
msb rm -f compose-ci
Delete the cache only when you no longer need it:
msb volume remove compose-ci-cache
Keep the named volume if you want a repository-specific image cache between trusted runs. Do not share a writable cache across repositories or trust boundaries.
</Step> </Steps> <Warning> Never mount the host Docker socket into the sandbox. Control of that socket is normally control of the host Docker daemon and defeats the microVM boundary. </Warning>