Skip to content

Image

Represents an image definition for a Daytona sandbox. Do not construct this class directly. Instead use one of its static factory methods, such as Image.base(), Image.debianSlim() or Image.fromDockerfile().

Accessors

contextList

Get Signature
get contextList(): Context[]
Returns

Context[]

The list of context files to be added to the image.


dockerfile

Get Signature
get dockerfile(): string

Returns:

  • string - The Dockerfile content.

Methods

base()

static base(image: string): Image

Creates an Image from an existing base image.

Parameters:

  • image string - The base image to use.

Returns:

  • Image - The Image instance.

Example:

const image = Image.base('python:3.12-slim-bookworm')

debianSlim()

static debianSlim(pythonVersion?: "3.9" | "3.10" | "3.11" | "3.12" | "3.13"): Image

Creates a Debian slim image based on the official Python Docker image.

Parameters:

  • pythonVersion? The Python version to use. - "3.9" | "3.10" | "3.11" | "3.12" | "3.13"

Returns:

  • Image - The Image instance.

Example:

const image = Image.debianSlim('3.12')

fromDockerfile()

static fromDockerfile(path: string): Image

Creates an Image from an existing Dockerfile.

Parameters:

  • path string - The path to the Dockerfile.

Returns:

  • Image - The Image instance.

Example:

const image = Image.fromDockerfile('Dockerfile')

addLocalDir()

addLocalDir(localPath: string, remotePath: string): Image

Adds a local directory to the image.

Parameters:

  • localPath string - The path to the local directory.
  • remotePath string - The path of the directory in the image.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.addLocalDir('src', '/home/daytona/src')

addLocalFile()

addLocalFile(localPath: string, remotePath: string): Image

Adds a local file to the image.

Parameters:

  • localPath string - The path to the local file.
  • remotePath string - The path of the file in the image.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.addLocalFile('requirements.txt', '/home/daytona/requirements.txt')

cmd()

cmd(cmd: string[]): Image

Sets the default command for the image.

Parameters:

  • cmd string[] - The command to set as the default command.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.cmd(['/bin/bash'])

dockerfileCommands()

dockerfileCommands(dockerfileCommands: string[], contextDir?: string): Image

Extends an image with arbitrary Dockerfile-like commands.

Parameters:

  • dockerfileCommands string[] - The commands to add to the Dockerfile.
  • contextDir? string - The path to the context directory.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.dockerfileCommands(['RUN echo "Hello, world!"'])

entrypoint()

entrypoint(entrypointCommands: string[]): Image

Sets the entrypoint for the image.

Parameters:

  • entrypointCommands string[] - The commands to set as the entrypoint.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.entrypoint(['/bin/bash'])

env()

env(envVars: Record<string, string>): Image

Sets environment variables in the image.

Parameters:

  • envVars Record<string, string> - The environment variables to set.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.env({ FOO: 'bar' })

pipInstall()

pipInstall(packages: string | string[], options?: PipInstallOptions): Image

Adds commands to install packages using pip.

Parameters:

  • packages The packages to install. - string | string[]
  • options? PipInstallOptions - The options for the pip install command.

Returns:

  • Image - The Image instance.

Example:

const image = Image.debianSlim('3.12').pipInstall('numpy', { findLinks: ['https://pypi.org/simple'] })

pipInstallFromPyproject()

pipInstallFromPyproject(pyprojectToml: string, options?: PyprojectOptions): Image

Installs dependencies from a pyproject.toml file.

Parameters:

  • pyprojectToml string - The path to the pyproject.toml file.
  • options? PyprojectOptions - The options for the pip install command.

Returns:

  • Image - The Image instance.

Example:

const image = Image.debianSlim('3.12')
image.pipInstallFromPyproject('pyproject.toml', { optionalDependencies: ['dev'] })

pipInstallFromRequirements()

pipInstallFromRequirements(requirementsTxt: string, options?: PipInstallOptions): Image

Installs dependencies from a requirements.txt file.

Parameters:

  • requirementsTxt string - The path to the requirements.txt file.
  • options? PipInstallOptions - The options for the pip install command.

Returns:

  • Image - The Image instance.

Example:

const image = Image.debianSlim('3.12')
image.pipInstallFromRequirements('requirements.txt', { findLinks: ['https://pypi.org/simple'] })

runCommands()

runCommands(...commands: (string | string[])[]): Image

Runs commands in the image.

Parameters:

  • commands …(string | string[])[] - The commands to run.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.runCommands(
'echo "Hello, world!"',
['bash', '-c', 'echo Hello, world, again!']
)

workdir()

workdir(dirPath: string): Image

Sets the working directory in the image.

Parameters:

  • dirPath string - The path to the working directory.

Returns:

  • Image - The Image instance.

Example:

const image = Image
.debianSlim('3.12')
.workdir('/home/daytona')

Context

Represents a context file to be added to the image.

Properties:

  • archivePath string - The path inside the archive file in object storage.
  • sourcePath string - The path to the source file or directory.

PipInstallOptions

Options for the pip install command.

Properties:

  • extraIndexUrls? string[] - The extra index URLs to use for the pip install command.
  • extraOptions? string - The extra options to use for the pip install command. Given string is passed directly to the pip install command.
  • findLinks? string[] - The find-links to use for the pip install command.
  • indexUrl? string - The index URL to use for the pip install command.
  • pre? boolean - Whether to install pre-release versions.

Extended by

  • PyprojectOptions

PyprojectOptions

Options for the pip install command from a pyproject.toml file.

Properties:

  • extraIndexUrls? string[] - The extra index URLs to use for the pip install command.
    • Inherited from: PipInstallOptions.extraIndexUrls
  • extraOptions? string - The extra options to use for the pip install command. Given string is passed directly to the pip install command.
    • Inherited from: PipInstallOptions.extraOptions
  • findLinks? string[] - The find-links to use for the pip install command.
    • Inherited from: PipInstallOptions.findLinks
  • indexUrl? string - The index URL to use for the pip install command.
    • Inherited from: PipInstallOptions.indexUrl
  • optionalDependencies? string[] - The optional dependencies to install.
  • pre? boolean - Whether to install pre-release versions.
    • Inherited from: PipInstallOptions.pre

Extends:

  • PipInstallOptions