View Source Dagger.Container (dagger_ex v0.1.1)

An OCI-compatible container, also known as a docker container.

Link to this section Summary

Functions

Initializes this container from a Dockerfile build.

Retrieves default arguments for future commands.

Retrieves a directory at the given path.

Retrieves an endpoint that clients can use to reach this container.

Retrieves entrypoint to be prepended to the arguments of all commands.

Retrieves the value of the specified environment variable.

Retrieves the list of environment variables passed to commands.

Retrieves this container after executing the specified command inside it.

Exit code of the last executed command. Zero means success.

Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants.

Retrieves the list of exposed ports.

Retrieves a file at the given path.

Initializes this container from a pulled base image.

fs(container) deprecated

Retrieves this container's root filesystem. Mounts are not included.

Retrieves a hostname which can be used by clients to reach this container.

A unique identifier for this container.

The unique image reference which can only be retrieved immediately after the 'Container.From' call.

Reads the container from an OCI tarball.

Retrieves the value of the specified label.

Retrieves the list of labels passed to container.

Retrieves the list of paths where a directory is mounted.

Creates a named sub-pipeline

The platform this container executes and publishes as.

Publishes this container as a new image to the specified address.

Retrieves this container's root filesystem. Mounts are not included.

The error stream of the last executed command.

The output stream of the last executed command.

Retrieves the user to be set for all commands.

Configures default arguments for future commands.

Retrieves this container plus a directory written at the given path.

Retrieves this container but with a different command entrypoint.

Retrieves this container plus the given environment variable.

Retrieves this container after executing the specified command inside it.

Retrieves this container plus the contents of the given file copied to the given path.

Initializes this container from this DirectoryID.

Retrieves this container plus the given label.

Retrieves this container plus a cache volume mounted at the given path.

Retrieves this container plus a directory mounted at the given path.

Retrieves this container plus a file mounted at the given path.

Retrieves this container plus a secret mounted into a file at the given path.

Retrieves this container plus a temporary directory mounted at the given path.

Retrieves this container plus a new file written at the given path.

Retrieves this container with a registry authentication for a given address.

Initializes this container from this DirectoryID.

Retrieves this container plus an env variable containing the given secret.

Establish a runtime dependency on a service.

Retrieves this container plus a socket forwarded to the given Unix socket path.

Retrieves this container with a different command user.

Retrieves this container with a different working directory.

Retrieves this container minus the given environment variable.

Retrieves this container minus the given environment label.

Retrieves this container after unmounting everything at the given path.

Retrieves this container without the registry authentication of a given address.

Retrieves this container with a previously added Unix socket removed.

Retrieves the working directory for all commands.

Link to this section Functions

Link to this function

build(container, context, optional_args \\ [])

View Source

Initializes this container from a Dockerfile build.

required-arguments

Required Arguments

  • context - Directory context used by the Dockerfile.

optional-arguments

Optional Arguments

  • dockerfile - Path to the Dockerfile to use.

Default: './Dockerfile'.

  • build_args - Additional build arguments.
  • target - Target build stage to build.
  • secrets - Secrets to pass to the build.

They will be mounted at /run/secrets/[secret-name].

Retrieves default arguments for future commands.

Link to this function

directory(container, path)

View Source

Retrieves a directory at the given path.

Mounts are included.

required-arguments

Required Arguments

  • path - The path of the directory to retrieve (e.g., "./src").
Link to this function

endpoint(container, optional_args \\ [])

View Source

Retrieves an endpoint that clients can use to reach this container.

If no port is specified, the first exposed port is used. If none exist an error is returned.

If a scheme is specified, a URL is returned. Otherwise, a host:port pair is returned.

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

optional-arguments

Optional Arguments

  • port - The exposed port number for the endpoint
  • scheme - Return a URL with the given scheme, eg. http for http://

Retrieves entrypoint to be prepended to the arguments of all commands.

Link to this function

env_variable(container, name)

View Source

Retrieves the value of the specified environment variable.

required-arguments

Required Arguments

  • name - The name of the environment variable to retrieve (e.g., "PATH").
Link to this function

env_variables(container)

View Source

Retrieves the list of environment variables passed to commands.

Link to this function

exec(container, optional_args \\ [])

View Source
This function is deprecated. Replaced by `withExec`.

Retrieves this container after executing the specified command inside it.

optional-arguments

Optional Arguments

  • args - Command to run instead of the container's default command (e.g., ["run", "main.go"]).
  • stdin - Content to write to the command's standard input before closing (e.g., "Hello world").
  • redirect_stdout - Redirect the command's standard output to a file in the container (e.g., "/tmp/stdout").
  • redirect_stderr - Redirect the command's standard error to a file in the container (e.g., "/tmp/stderr").
  • experimental_privileged_nesting - Provide dagger access to the executed command. Do not use this option unless you trust the command being executed. The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.

Exit code of the last executed command. Zero means success.

Will execute default command if none is set, or error if there's no default.

Link to this function

export(container, path, optional_args \\ [])

View Source

Writes the container as an OCI tarball to the destination file path on the host for the specified platform variants.

Return true on success. It can also publishes platform variants.

required-arguments

Required Arguments

  • path - Host's destination path (e.g., "./tarball"). Path can be relative to the engine's workdir or absolute.

optional-arguments

Optional Arguments

  • platform_variants - Identifiers for other platform specific containers. Used for multi-platform image.
Link to this function

exposed_ports(container)

View Source

Retrieves the list of exposed ports.

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

Retrieves a file at the given path.

Mounts are included.

required-arguments

Required Arguments

  • path - The path of the file to retrieve (e.g., "./README.md").
Link to this function

from(container, address)

View Source

Initializes this container from a pulled base image.

required-arguments

Required Arguments

  • address - Image's address from its registry.

Formatted as [host]/[user]/[repo]:[tag] (e.g., "docker.io/dagger/dagger:main").

This function is deprecated. Replaced by `rootfs`.

Retrieves this container's root filesystem. Mounts are not included.

Retrieves a hostname which can be used by clients to reach this container.

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

A unique identifier for this container.

The unique image reference which can only be retrieved immediately after the 'Container.From' call.

Link to this function

import(container, source, optional_args \\ [])

View Source

Reads the container from an OCI tarball.

NOTE: this involves unpacking the tarball to an OCI store on the host at $XDG_CACHE_DIR/dagger/oci. This directory can be removed whenever you like.

required-arguments

Required Arguments

  • source - File to read the container from.

optional-arguments

Optional Arguments

  • tag - Identifies the tag to import from the archive, if the archive bundles multiple tags.

Retrieves the value of the specified label.

required-arguments

Required Arguments

  • name -

Retrieves the list of labels passed to container.

Retrieves the list of paths where a directory is mounted.

Link to this function

pipeline(container, name, optional_args \\ [])

View Source

Creates a named sub-pipeline

required-arguments

Required Arguments

  • name - Pipeline name.

optional-arguments

Optional Arguments

  • description - Pipeline description.
  • labels - Pipeline labels.

The platform this container executes and publishes as.

Link to this function

publish(container, address, optional_args \\ [])

View Source

Publishes this container as a new image to the specified address.

Publish returns a fully qualified ref. It can also publish platform variants.

required-arguments

Required Arguments

  • address - Registry's address to publish the image to.

Formatted as [host]/[user]/[repo]:[tag] (e.g. "docker.io/dagger/dagger:main").

optional-arguments

Optional Arguments

  • platform_variants - Identifiers for other platform specific containers. Used for multi-platform image.

Retrieves this container's root filesystem. Mounts are not included.

The error stream of the last executed command.

Will execute default command if none is set, or error if there's no default.

The output stream of the last executed command.

Will execute default command if none is set, or error if there's no default.

Retrieves the user to be set for all commands.

Link to this function

with_default_args(container, optional_args \\ [])

View Source

Configures default arguments for future commands.

optional-arguments

Optional Arguments

  • args - Arguments to prepend to future executions (e.g., ["-v", "--no-cache"]).
Link to this function

with_directory(container, path, directory, optional_args \\ [])

View Source

Retrieves this container plus a directory written at the given path.

required-arguments

Required Arguments

  • path - Location of the written directory (e.g., "/tmp/directory").
  • directory - Identifier of the directory to write

optional-arguments

Optional Arguments

  • exclude - Patterns to exclude in the written directory (e.g., ["node_modules/**", ".gitignore", ".git/"]).
  • include - Patterns to include in the written directory (e.g., ["*.go", "go.mod", "go.sum"]).
  • owner - A user:group to set for the directory and its contents.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_entrypoint(container, args)

View Source

Retrieves this container but with a different command entrypoint.

required-arguments

Required Arguments

  • args - Entrypoint to use for future executions (e.g., ["go", "run"]).
Link to this function

with_env_variable(container, name, value)

View Source

Retrieves this container plus the given environment variable.

required-arguments

Required Arguments

  • name - The name of the environment variable (e.g., "HOST").
  • value - The value of the environment variable. (e.g., "localhost").
Link to this function

with_exec(container, args, optional_args \\ [])

View Source

Retrieves this container after executing the specified command inside it.

required-arguments

Required Arguments

  • args - Command to run instead of the container's default command (e.g., ["run", "main.go"]).

If empty, the container's default command is used.

optional-arguments

Optional Arguments

  • skip_entrypoint - If the container has an entrypoint, ignore it for args rather than using it to wrap them.
  • stdin - Content to write to the command's standard input before closing (e.g., "Hello world").
  • redirect_stdout - Redirect the command's standard output to a file in the container (e.g., "/tmp/stdout").
  • redirect_stderr - Redirect the command's standard error to a file in the container (e.g., "/tmp/stderr").
  • experimental_privileged_nesting - Provides dagger access to the executed command.

Do not use this option unless you trust the command being executed. The command being executed WILL BE GRANTED FULL ACCESS TO YOUR HOST FILESYSTEM.

  • insecure_root_capabilities - Execute the command with all root capabilities. This is similar to running a command with "sudo" or executing docker run with the --privileged flag. Containerization does not provide any security guarantees when using this option. It should only be used when absolutely necessary and only with trusted commands.
Link to this function

with_exposed_port(container, port, optional_args \\ [])

View Source

Expose a network port.

Exposed ports serve two purposes:

  • For health checks and introspection, when running services
  • For setting the EXPOSE OCI field when publishing the container

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

required-arguments

Required Arguments

  • port - Port number to expose

optional-arguments

Optional Arguments

  • protocol - Transport layer network protocol
  • description - Optional port description
Link to this function

with_file(container, path, source, optional_args \\ [])

View Source

Retrieves this container plus the contents of the given file copied to the given path.

required-arguments

Required Arguments

  • path - Location of the copied file (e.g., "/tmp/file.txt").
  • source - Identifier of the file to copy.

optional-arguments

Optional Arguments

  • permissions - Permission given to the copied file (e.g., 0600).

Default: 0644.

  • owner - A user:group to set for the file.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

This function is deprecated. Replaced by `withRootfs`.

Initializes this container from this DirectoryID.

required-arguments

Required Arguments

  • id -
Link to this function

with_label(container, name, value)

View Source

Retrieves this container plus the given label.

required-arguments

Required Arguments

  • name - The name of the label (e.g., "org.opencontainers.artifact.created").
  • value - The value of the label (e.g., "2023-01-01T00:00:00Z").
Link to this function

with_mounted_cache(container, path, cache, optional_args \\ [])

View Source

Retrieves this container plus a cache volume mounted at the given path.

required-arguments

Required Arguments

  • path - Location of the cache directory (e.g., "/cache/node_modules").
  • cache - Identifier of the cache volume to mount.

optional-arguments

Optional Arguments

  • source - Identifier of the directory to use as the cache volume's root.
  • sharing - Sharing mode of the cache volume.
  • owner - A user:group to set for the mounted cache directory.

Note that this changes the ownership of the specified mount along with the initial filesystem provided by source (if any). It does not have any effect if/when the cache has already been created.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_mounted_directory(container, path, source, optional_args \\ [])

View Source

Retrieves this container plus a directory mounted at the given path.

required-arguments

Required Arguments

  • path - Location of the mounted directory (e.g., "/mnt/directory").
  • source - Identifier of the mounted directory.

optional-arguments

Optional Arguments

  • owner - A user:group to set for the mounted directory and its contents.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_mounted_file(container, path, source, optional_args \\ [])

View Source

Retrieves this container plus a file mounted at the given path.

required-arguments

Required Arguments

  • path - Location of the mounted file (e.g., "/tmp/file.txt").
  • source - Identifier of the mounted file.

optional-arguments

Optional Arguments

  • owner - A user or user:group to set for the mounted file.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_mounted_secret(container, path, source, optional_args \\ [])

View Source

Retrieves this container plus a secret mounted into a file at the given path.

required-arguments

Required Arguments

  • path - Location of the secret file (e.g., "/tmp/secret.txt").
  • source - Identifier of the secret to mount.

optional-arguments

Optional Arguments

  • owner - A user:group to set for the mounted secret.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_mounted_temp(container, path)

View Source

Retrieves this container plus a temporary directory mounted at the given path.

required-arguments

Required Arguments

  • path - Location of the temporary directory (e.g., "/tmp/temp_dir").
Link to this function

with_new_file(container, path, optional_args \\ [])

View Source

Retrieves this container plus a new file written at the given path.

required-arguments

Required Arguments

  • path - Location of the written file (e.g., "/tmp/file.txt").

optional-arguments

Optional Arguments

  • contents - Content of the file to write (e.g., "Hello world!").
  • permissions - Permission given to the written file (e.g., 0600).

Default: 0644.

  • owner - A user:group to set for the file.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_registry_auth(container, address, username, secret)

View Source

Retrieves this container with a registry authentication for a given address.

required-arguments

Required Arguments

  • address - Registry's address to bind the authentication to. Formatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main).
  • username - The username of the registry's account (e.g., "Dagger").
  • secret - The API key, password or token to authenticate to this registry.
Link to this function

with_rootfs(container, id)

View Source

Initializes this container from this DirectoryID.

required-arguments

Required Arguments

  • id -
Link to this function

with_secret_variable(container, name, secret)

View Source

Retrieves this container plus an env variable containing the given secret.

required-arguments

Required Arguments

  • name - The name of the secret variable (e.g., "API_SECRET").
  • secret - The identifier of the secret value.
Link to this function

with_service_binding(container, alias, service)

View Source

Establish a runtime dependency on a service.

The service will be started automatically when needed and detached when it is no longer needed, executing the default command if none is set.

The service will be reachable from the container via the provided hostname alias.

The service dependency will also convey to any files or directories produced by the container.

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

required-arguments

Required Arguments

  • alias - A name that can be used to reach the service from the container
  • service - Identifier of the service container
Link to this function

with_unix_socket(container, path, source, optional_args \\ [])

View Source

Retrieves this container plus a socket forwarded to the given Unix socket path.

required-arguments

Required Arguments

  • path - Location of the forwarded Unix socket (e.g., "/tmp/socket").
  • source - Identifier of the socket to forward.

optional-arguments

Optional Arguments

  • owner - A user:group to set for the mounted socket.

The user and group can either be an ID (1000:1000) or a name (foo:bar).

If the group is omitted, it defaults to the same as the user.

Link to this function

with_user(container, name)

View Source

Retrieves this container with a different command user.

required-arguments

Required Arguments

  • name - The user to set (e.g., "root").
Link to this function

with_workdir(container, path)

View Source

Retrieves this container with a different working directory.

required-arguments

Required Arguments

  • path - The path to set as the working directory (e.g., "/app").
Link to this function

without_env_variable(container, name)

View Source

Retrieves this container minus the given environment variable.

required-arguments

Required Arguments

  • name - The name of the environment variable (e.g., "HOST").
Link to this function

without_exposed_port(container, port, optional_args \\ [])

View Source

Unexpose a previously exposed port.

Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

required-arguments

Required Arguments

  • port - Port number to unexpose

optional-arguments

Optional Arguments

  • protocol - Port protocol to unexpose
Link to this function

without_label(container, name)

View Source

Retrieves this container minus the given environment label.

required-arguments

Required Arguments

  • name - The name of the label to remove (e.g., "org.opencontainers.artifact.created").
Link to this function

without_mount(container, path)

View Source

Retrieves this container after unmounting everything at the given path.

required-arguments

Required Arguments

  • path - Location of the cache directory (e.g., "/cache/node_modules").
Link to this function

without_registry_auth(container, address)

View Source

Retrieves this container without the registry authentication of a given address.

required-arguments

Required Arguments

  • address - Registry's address to remove the authentication from. Formatted as [host]/[user]/[repo]:[tag] (e.g. docker.io/dagger/dagger:main).
Link to this function

without_unix_socket(container, path)

View Source

Retrieves this container with a previously added Unix socket removed.

required-arguments

Required Arguments

  • path - Location of the socket to remove (e.g., "/tmp/socket").

Retrieves the working directory for all commands.