Skip to main content
You can test Templates locally by converting them to a Docker-compatible container images that you can build and run locally.
E2B Templates do not map 1:1 to Dockerfiles. Only a limited set of methods are supported and converted to equivalent Docker instructions.See Compatibility for more details.

Example

Create a template file:
template.ts
import { Template } from "e2b";

export const template = Template()
  .fromBaseImage()
  .setEnvs({
    HELLO: "Hello, World!",
  })
  .runCmd("echo $HELLO")
Then, create a conversion script to convert the template to a Dockerfile definition:
dev.ts
import fs from "fs";
import { Template } from "e2b";
import { template } from "./template";

fs.writeFileSync("Dockerfile", Template.toDockerfile(template));
Run the conversion script, forwarding the output to a new Dockerfile file:
npx tsx dev.ts
Should produce a Dockerfile in the current directory with the following content:
FROM e2bdev/base
ENV HELLO="Hello, World!"
RUN echo $HELLO
Build a container image from the Dockerfile and run it locally:
docker build -t template .
docker run template

Compatibility

  • TypeScript
  • Python
MethodSupportedDocker Equivalent
fromBaseImage()FROM e2bdev/base
fromUbuntuImage()FROM ubuntu:version
fromNodeImage()FROM node:version
fromPythonImage()FROM python:version
fromDebianImage()FROM debian:version
fromImage()FROM custom-image
setEnvs()ENV key=value
runCmd()RUN command
setStartCmd()ENTRYPOINT command
setWorkdir()WORKDIR path
setUser()USER user
copy()COPY src dest
aptInstall()RUN apt-get update && apt-get install -y package
pipInstall()RUN pip install package
npmInstall()RUN npm install package
gitClone()RUN git clone repository
makeSymlink()RUN ln -s src dest
fromTemplate()Not supported - templates based on other templates cannot be converted to Dockerfile
fromDockerfile()Not supported - parsing Dockerfiles is not supported for local development
fromRegistry()Not supported - registry authentication not supported for local development
fromAWSRegistry()Not supported - AWS registry authentication not supported for local development
fromGCPRegistry()Not supported - GCP registry authentication not supported for local development
skipCache()Not supported - cache invalidation is not applicable for Dockerfile conversion
setReadyCmd()Not supported - ready commands are E2B-specific and not part of Docker