Skip to main content

Install Docker

Use the official installation script from get.docker.com. The hello-world container validates the installation.
// template.ts
import { Template } from 'e2b'

export const template = Template()
  .fromUbuntuImage('25.04')
  .runCmd('curl -fsSL https://get.docker.com | sudo sh')
  .runCmd('sudo docker run --rm hello-world')

Build the template

You may need to increase RAM if Docker containers cause out-of-memory errors.
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as dockerTemplate } from './template'

Template.build(dockerTemplate, 'docker', {
  cpuCount: 2,
  memoryMB: 2048,
  onBuildLogs: defaultBuildLogger(),
})

Run containers

Run an Alpine container that prints a hello message.
// sandbox.ts
import { Sandbox } from 'e2b'

const sbx = await Sandbox.create('docker')

const result = await sbx.commands.run('sudo docker run --rm alpine echo "Hello from Alpine!"')
console.log(result.stdout)

await sbx.kill()