docker:dind image, starts Docker inside the sandbox, waits for it to be ready, and then opens an interactive shell. From there, Docker commands run against the daemon inside the sandbox, not your host.
Start Docker in a sandbox
- Starts the
docker:dindimage in a sandbox nameddocker-demo. - Mounts a disk-backed named volume called
docker-dataat/var/lib/docker, where Docker stores images, containers, and build cache. - Runs the inline
startscript as the entrypoint. The script starts Docker, waits until it is ready, and then opens a shell.
--mount-named docker-data:/var/lib/docker:kind=disk,size=10G is idempotent. If docker-data does not exist, the CLI creates it before starting the sandbox. If it already exists with compatible disk settings, the same command reuses it, so pulled images and created containers can survive msb rm docker-demo.
Run a container
From the sandbox shell, run a nested Ubuntu container:exit to return to the docker-demo sandbox shell.
You can also verify the daemon with a short non-interactive command:
Cleanup
docker-data only when you no longer need the images, containers, and build cache stored by the nested daemon.
Details
The disk-backed named mount gives Docker its own ext4 filesystem at/var/lib/docker. That matters because the sandbox root filesystem is already overlay-backed, and Docker’s default storage driver also uses overlay layers. Keeping Docker’s data root on a dedicated disk-backed volume avoids putting Docker’s overlay storage directly on top of the sandbox root overlay.
Notes
- Memory. The recipe uses
--memory 2G. Increase it for larger builds or memory-hungry containers. - Not the same as Sandbox in Docker. That recipe covers the opposite direction.