Skip to content
View as Markdown

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.debian_slim(), or Image.from_dockerfile().

Constructors

new Image()

def initialize(dockerfile:, context_list:)

Parameters:

  • dockerfile String, nil - The Dockerfile content
  • context_list Array<Context> - List of context files

Returns:

  • Image - a new instance of Image

Methods

dockerfile()

def dockerfile()

Returns:

  • String, nil - The generated Dockerfile for the image

context_list()

def context_list()

Returns:

  • Array\<Context\> - List of context files for the image

pip_install()

def pip_install(*packages, find_links:, index_url:, extra_index_urls:, pre:, extra_options:)

Adds commands to install packages using pip

Parameters:

  • packages Array<String> - The packages to install
  • find_links Array<String>, nil - The find-links to use
  • index_url String, nil - The index URL to use
  • extra_index_urls Array<String>, nil - The extra index URLs to use
  • pre Boolean - Whether to install pre-release packages
  • extra_options String - Additional options to pass to pip

Returns:

  • Image - The image with the pip install commands added

Examples:

image = Image.debian_slim("3.12").pip_install("requests", "pandas")

pip_install_from_requirements()

def pip_install_from_requirements(requirements_txt, find_links:, index_url:, extra_index_urls:, pre:, extra_options:)

Installs dependencies from a requirements.txt file

Parameters:

  • requirements_txt String - The path to the requirements.txt file
  • find_links Array<String>, nil - The find-links to use
  • index_url String, nil - The index URL to use
  • extra_index_urls Array<String>, nil - The extra index URLs to use
  • pre Boolean - Whether to install pre-release packages
  • extra_options String - Additional options to pass to pip

Returns:

  • Image - The image with the pip install commands added

Raises:

  • Sdk:Error - If the requirements file does not exist

Examples:

image = Image.debian_slim("3.12").pip_install_from_requirements("requirements.txt")

pip_install_from_pyproject()

def pip_install_from_pyproject(pyproject_toml, optional_dependencies:, find_links:, index_url:, extra_index_url:, pre:, extra_options:)

Installs dependencies from a pyproject.toml file

Parameters:

  • pyproject_toml String - The path to the pyproject.toml file
  • optional_dependencies Array<String> - The optional dependencies to install
  • find_links String, nil - The find-links to use
  • index_url String, nil - The index URL to use
  • extra_index_url String, nil - The extra index URL to use
  • pre Boolean - Whether to install pre-release packages
  • extra_options String - Additional options to pass to pip

Returns:

  • Image - The image with the pip install commands added

Raises:

  • Sdk:Error - If pyproject.toml parsing is not supported

Examples:

image = Image.debian_slim("3.12").pip_install_from_pyproject("pyproject.toml", optional_dependencies: ["dev"])

add_local_file()

def add_local_file(local_path, remote_path)

Adds a local file to the image

Parameters:

  • local_path String - The path to the local file
  • remote_path String - The path to the file in the image

Returns:

  • Image - The image with the local file added

Examples:

image = Image.debian_slim("3.12").add_local_file("package.json", "/home/daytona/package.json")

add_local_dir()

def add_local_dir(local_path, remote_path)

Adds a local directory to the image

Parameters:

  • local_path String - The path to the local directory
  • remote_path String - The path to the directory in the image

Returns:

  • Image - The image with the local directory added

Examples:

image = Image.debian_slim("3.12").add_local_dir("src", "/home/daytona/src")

run_commands()

def run_commands(*commands)

Runs commands in the image

Parameters:

  • commands Array<String> - The commands to run

Returns:

  • Image - The image with the commands added

Examples:

image = Image.debian_slim("3.12").run_commands('echo "Hello, world!"', 'echo "Hello again!"')

env()

def env(env_vars)

Sets environment variables in the image

Parameters:

  • env_vars Hash<String, String> - The environment variables to set

Returns:

  • Image - The image with the environment variables added

Raises:

  • Sdk:Error -

Examples:

image = Image.debian_slim("3.12").env({"PROJECT_ROOT" => "/home/daytona"})

workdir()

def workdir(path)

Sets the working directory in the image

Parameters:

  • path String - The path to the working directory

Returns:

  • Image - The image with the working directory added

Examples:

image = Image.debian_slim("3.12").workdir("/home/daytona")

entrypoint()

def entrypoint(entrypoint_commands)

Sets the entrypoint for the image

Parameters:

  • entrypoint_commands Array<String> - The commands to set as the entrypoint

Returns:

  • Image - The image with the entrypoint added

Examples:

image = Image.debian_slim("3.12").entrypoint(["/bin/bash"])

cmd()

def cmd(cmd)

Sets the default command for the image

Parameters:

  • cmd Array<String> - The commands to set as the default command

Returns:

  • Image - The image with the default command added

Examples:

image = Image.debian_slim("3.12").cmd(["/bin/bash"])

dockerfile_commands()

def dockerfile_commands(dockerfile_commands, context_dir:)

Adds arbitrary Dockerfile-like commands to the image

Parameters:

  • dockerfile_commands Array<String> - The commands to add to the Dockerfile
  • context_dir String, nil - The path to the context directory

Returns:

  • Image - The image with the Dockerfile commands added

Examples:

image = Image.debian_slim("3.12").dockerfile_commands(["RUN echo 'Hello, world!'"])