Skip to main content

Types

In addition to basic types (string, boolean, integer, arrays...), the Dagger API also provides powerful core types which serve as both arguments and return values for Dagger Functions.

note

The types listed on this page are indicative and not exhaustive. For a complete list of supported types and their fields, refer to the Dagger API reference.

The following table lists available types and what they represent:

TypeDescription
CacheVolumeA directory whose contents persist across runs
ContainerAn OCI-compatible container
CurrentModuleThe current Dagger module and its context
EngineThe Dagger Engine configuration and state
DirectoryA directory (local path or Git reference)
EnvVariableAn environment variable name and value
EnvAn environment variable name and value
FileA file
GitRepositoryA Git repository
GitRefA Git reference (tag, branch, or commit)
HostThe Dagger host environment
LLMA Large Language Model (LLM)
ModuleA Dagger module
PortA port exposed by a container
SecretA secret credential like a password, access token or key)
ServiceA content-addressed service providing TCP connectivity
SocketA Unix or TCP/IP socket that can be mounted into a container
TerminalAn interactive terminal session

Each type exposes additional fields. Some of these are discussed below.

Container

The Container type represents the state of an OCI-compatible container. This Container object is not merely a string referencing an image on a remote registry. It is the actual state of a container, managed by the Dagger Engine, and passed to a Dagger Function's code as if it were just another variable.

Common operations

Some of the common operations used on the Container type include:

FieldDescription
fromInitializes the container from a specified base image
asServiceTurns the container into a Service
asTarballReturns a serialized tarball of the container as a File
export / importWrites / reads the container as an OCI tarball to / from a file path on the host
publishPublishes the container image to a registry
stdout / stderrReturns the output / error stream of the last executed command
withDirectory / withMountedDirectoryReturns the container plus a directory copied / mounted at the given path
withEntrypointReturns the container with a custom entrypoint command
withExecReturns the container after executing a command inside it
withFile / withMountedFileReturns the container plus a file copied / mounted at the given path
withMountedCacheReturns the container plus a cache volume mounted at the given path
withRegistryAuthReturns the container with registry authentication configured
withWorkdirReturns the container configured with a specific working directory
withServiceBindingReturns the container with runtime dependency on another Service
terminalOpens an interactive terminal for this container

CurrentModule

The CurrentModule type provides capabilities to introspect the Dagger Function's module and interface between the current execution environment and the Dagger API.

Common operations

Some of the common operations available on the CurrentModule type include:

FieldDescription
sourceReturns the directory containing the module's source code
workdirLoads and returns a directory from the module's working directory, including any changes that may have been made to it during function execution
workdirFileLoads and returns a file from the module's working directory, including any changes that may have been made to it during function execution

Directory

Dagger Functions do not have access to the filesystem of the host you invoke the Dagger Function from (i.e. the host you execute a CLI command like dagger from). Instead, host files and directories need to be explicitly passed as command-line arguments to Dagger Functions.

There are two important reasons for this.

  • Reproducibility: By providing a call-time mechanism to define and control the files available to a Dagger Function, Dagger guards against creating hidden dependencies on ambient properties of the host filesystem that could change at any moment.
  • Security: By forcing you to explicitly specify which host files and directories a Dagger Function "sees" on every call, Dagger ensures that you're always 100% in control. This reduces the risk of third-party Dagger Functions gaining access to your data.

The Directory type represents the state of a directory. This could be either a local directory path or a remote Git reference.

Common operations

Some of the common operations available on the Directory type include:

FieldDescription
dockerBuildBuilds a new Docker container from the directory
entriesReturns a list of files and directories in the directory
exportWrites the contents of the directory to a path on the host
fileReturns a file at the given path as a File
withFile / withFilesReturns the directory plus the file(s) copied to the given path

File

The File type represents a single file. Some of its important fields are:

Common operations

FieldDescription
contentsReturns the contents of the file
exportWrites the file to a path on the host

Env

The Env type represents an environment consisting of inputs and desired outputs, for use by an LLM. For example, an environment might provide a Directory, a Container, a custom module, and a string variable as inputs, and request a Container as output.

Common operations

Some of the common operations available on the Env type include:

FieldDescription
inputRetrieves an input value by name
inputsRetrieves all input values
outputRetrieves an output value by name
outputsRetrieves all output values
withContainerInputCreates or updates an input of type Container
withContainerOutputDeclare a desired output of type Container
withDirectoryInputCreates or updates an input of type Directory
withDirectoryOutputDeclare a desired output of type Directory
withFileInputCreates or updates an input of type File
withFileOutputDeclare a desired output of type File
with[Object]InputCreates or updates an input of type Object
with[Object]OutputDeclare a desired output of type Object

Secret

Dagger allows you to utilize confidential information ("secrets") such as passwords, API keys, SSH keys and so on, without exposing those secrets in plaintext logs, writing them into the filesystem of containers you're building, or inserting them into the cache. The Secret type is used to represent these secret values.

Common operations

Some of the common operations you can perform with a Secret include:

FieldDescription
nameReturns the name of the secret
plaintextReturns the plaintext value of the secret

Service

The Service type represents a content-addressed service providing TCP connectivity.

Common operations

Some of the common operations you can perform with a Service include:

FieldDescription
endpointReturns a URL or host:port pair to reach the service
hostnameReturns a hostname to reach the service
portsReturns the list of ports provided by the service
upCreates a tunnel that forwards traffic from the caller's network to the service