Docker template
This template installs Docker Engine and Docker Compose. Ubuntu starts the Docker daemon as a system service when the sandbox boots.
mjs
import { Sandbox, Template } from "@abox-dev/sdk";
const templateName = process.env.TEMPLATE_NAME ?? "docker-runtime";
const template = Template()
.fromUbuntuImage("24.04")
.aptInstall(["docker.io", "docker-compose-v2"])
.runCmd("sudo docker pull alpine:3.22");
await Template.build(template, templateName, {
cpuCount: 2,
memoryMB: 2_048,
});
const sandbox = await Sandbox.create(templateName);
try {
const result = await sandbox.commands.run(
'sudo docker run --rm --network none alpine:3.22 echo "Hello from Docker" && sudo docker compose version',
);
console.log(result.stdout);
} finally {
await sandbox.kill();
}The Alpine image is pulled while the template is built. New sandboxes therefore start with the image already available. The example runs a container without a network and then prints the installed Compose version.
Rebuild the template when you need another base image or Docker package version.