Skip to content

Commit 1747296

Browse files
authored
Add Docker template example (#99)
* Add Docker template example documentation Add a new template example showing how to create a sandbox with Docker installed. Uses the official get.docker.com script for installation and validates with hello-world during build. * Match docker template format with other examples - Remove section headers - Use inline code comments instead of prose - Use sbx variable and sbx.kill() pattern - Simplify template name to 'docker' * Add section headers and prose to docker template * Add RAM note to docker template build section * Fix Python Sandbox.create() in docker example * Remove intro text from docker template * Match Python Sandbox pattern with other templates * Fix SDK patterns and add prose to docker template - Add await to sbx.kill() in TypeScript - Use Sandbox.create() pattern in Python - Add brief description to Run containers section * Improve build section with clearer RAM recommendation Replace Note with inline prose explaining recommended specs (2 CPUs, 2 GB RAM) and bold warning about lower RAM causing OOM errors. * Address review feedback on docker template - Add "run" to hello-world validation sentence - Simplify RAM warning text
1 parent 1ecb1de commit 1747296

2 files changed

Lines changed: 94 additions & 1 deletion

File tree

docs.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
"docs/template/examples/nextjs-bun",
122122
"docs/template/examples/expo",
123123
"docs/template/examples/desktop",
124-
"docs/template/examples/claude-code"
124+
"docs/template/examples/claude-code",
125+
"docs/template/examples/docker"
125126
]
126127
},
127128
"docs/template/migration-v2",

docs/template/examples/docker.mdx

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
---
2+
title: "Docker"
3+
description: "Sandbox with Docker installed for running containers"
4+
---
5+
6+
## Install Docker
7+
8+
Use the official installation script from [get.docker.com](https://get.docker.com). The `hello-world` container run validates the installation.
9+
10+
<CodeGroup>
11+
```typescript JavaScript & TypeScript
12+
// template.ts
13+
import { Template } from 'e2b'
14+
15+
export const template = Template()
16+
.fromUbuntuImage('25.04')
17+
.runCmd('curl -fsSL https://get.docker.com | sudo sh')
18+
.runCmd('sudo docker run --rm hello-world')
19+
```
20+
21+
```python Python
22+
# template.py
23+
from e2b import Template
24+
25+
template = (
26+
Template()
27+
.from_ubuntu_image("25.04")
28+
.run_cmd("curl -fsSL https://get.docker.com | sudo sh")
29+
.run_cmd("sudo docker run --rm hello-world")
30+
)
31+
```
32+
</CodeGroup>
33+
34+
## Build the template
35+
36+
We recommend at least 2 CPUs and 2 GB of RAM for running Docker containers. **With lower RAM, your sandbox might run out of memory.**
37+
38+
<CodeGroup>
39+
```typescript JavaScript & TypeScript
40+
// build.ts
41+
import { Template, defaultBuildLogger } from 'e2b'
42+
import { template as dockerTemplate } from './template'
43+
44+
Template.build(dockerTemplate, 'docker', {
45+
cpuCount: 2,
46+
memoryMB: 2048,
47+
onBuildLogs: defaultBuildLogger(),
48+
})
49+
```
50+
51+
```python Python
52+
# build.py
53+
from e2b import Template, default_build_logger
54+
from .template import template as dockerTemplate
55+
56+
Template.build(dockerTemplate, 'docker',
57+
cpu_count=2,
58+
memory_mb=2048,
59+
on_build_logs=default_build_logger(),
60+
)
61+
```
62+
</CodeGroup>
63+
64+
## Run containers
65+
66+
Run an Alpine container that prints a hello message.
67+
68+
<CodeGroup>
69+
```typescript JavaScript & TypeScript
70+
// sandbox.ts
71+
import { Sandbox } from 'e2b'
72+
73+
const sbx = await Sandbox.create('docker')
74+
75+
const result = await sbx.commands.run('sudo docker run --rm alpine echo "Hello from Alpine!"')
76+
console.log(result.stdout)
77+
78+
await sbx.kill()
79+
```
80+
81+
```python Python
82+
# sandbox.py
83+
from e2b import Sandbox
84+
85+
sbx = Sandbox.create('docker')
86+
87+
result = sbx.commands.run('sudo docker run --rm alpine echo "Hello from Alpine!"')
88+
print(result.stdout)
89+
90+
sbx.kill()
91+
```
92+
</CodeGroup>

0 commit comments

Comments
 (0)