compose.yaml).
A sandbox on the vm runtime can run Docker, so it can run that file exactly as it is. This opens up several uses:
- An agent can build a feature against a real database, instead of a fake one.
- Integration tests can start the whole stack, run, and throw everything away afterwards.
- A development environment can stay up for days. It sleeps with every container still running, so the next morning the stack is exactly where it was, data included.
A stack with Postgres, from a compose file
1
A VM sandbox with Docker running
This sandbox starts from Docker’s official image and runs the Docker daemon (the background service that manages
containers) as its main program. The last line waits until the daemon is ready:
2
The project's compose file
In your own project, this file is already in the repository. For this example we write a small one: a Postgres
database, with a table and two rows created when it first starts.
3
Bring it up
Downloading the container images takes longer than an exec allows, so
sbx.run() runs the command in the
background and waits for it. --wait makes Docker Compose wait until every service reports that it is healthy.4
Use it
Now the agent, your tests or you yourself can work with the real database:
It sleeps with the stack running
If you leave the sandbox alone, it goes to sleep after its idle timeout. On thevm runtime, sleep keeps every
process: the Docker daemon, the Postgres container, and the database’s data both in memory and on disk. The next
call finds the stack still running, including the row added above.
docker compose up again after a wake, to reload data, or to wait for health checks.
Clean up
Patterns
These are the most common ways to use a Docker sandbox:Docker needs the
vm runtime, and needs: ["docker"] selects it for you. Images are downloaded from public
registries, or from your own private registry once you store a registry login.Related
Runtimes
What the
vm runtime adds, and when you need it.Sleep and wake
What sleep keeps on each runtime.