Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@
"docs/template/examples/nextjs-bun",
"docs/template/examples/expo",
"docs/template/examples/desktop",
"docs/template/examples/claude-code"
"docs/template/examples/claude-code",
"docs/template/examples/docker"
]
},
"docs/template/migration-v2",
Expand Down
94 changes: 94 additions & 0 deletions docs/template/examples/docker.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: "Docker"
description: "Sandbox with Docker installed for running containers"
---

## Install Docker

Use the official installation script from [get.docker.com](https://get.docker.com). The `hello-world` container validates the installation.

<CodeGroup>
```typescript JavaScript & TypeScript
// 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')
```

```python Python
# template.py
from e2b import Template

template = (
Template()
.from_ubuntu_image("25.04")
.run_cmd("curl -fsSL https://get.docker.com | sudo sh")
.run_cmd("sudo docker run --rm hello-world")
)
```
</CodeGroup>

## Build the template

<Note>
You may need to increase RAM if Docker containers cause out-of-memory errors.
</Note>

<CodeGroup>
```typescript JavaScript & TypeScript
// build.ts
import { Template, defaultBuildLogger } from 'e2b'
import { template as dockerTemplate } from './template'

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

```python Python
# build.py
from e2b import Template, default_build_logger
from .template import template as dockerTemplate

Template.build(dockerTemplate, 'docker',
cpu_count=2,
memory_mb=2048,
on_build_logs=default_build_logger(),
)
```
</CodeGroup>

## Run containers

Run an Alpine container that prints a hello message.

<CodeGroup>
```typescript JavaScript & TypeScript
// 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()
```

```python Python
# sandbox.py
from e2b import Sandbox

sbx = Sandbox.create('docker')

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

sbx.kill()
```
</CodeGroup>