Skip to main content

Core 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
FileA file
GitRepositoryA Git repository
GitRefA Git reference (tag, branch, or commit)
HostThe Dagger host environment
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.

Some of the Container type's important fields are:

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

Directory

The Directory type represents the state of a directory. This could be either a local directory path or a remote Git reference. Some of its important fields are:

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:

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

Service

The Service type represents a content-addressed service providing TCP connectivity. Some of its important fields are:

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

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. Some of its important fields are:

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

CurrentModule

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

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