Skip to content
View as Markdown

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().

get contextList(): Context[]

Context[]

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


get dockerfile(): string

Returns:

  • string - The Dockerfile content.
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')

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')

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(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(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: 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: 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(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(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(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(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(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(...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(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')

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.

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.
  • 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