Struct dagger_sdk::Container

source ·
pub struct Container {
    pub proc: Arc<Child>,
    pub selection: Selection,
    pub conn: ConnectParams,
}

Fields§

§proc: Arc<Child>§selection: Selection§conn: ConnectParams

Implementations§

source§

impl Container

source

pub fn build(&self, context: DirectoryId) -> Container

Initializes this container from a Dockerfile build.

Arguments
  • context - Directory context used by the Dockerfile.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn build_opts<'a>( &self, context: DirectoryId, opts: ContainerBuildOpts<'a> ) -> Container

Initializes this container from a Dockerfile build.

Arguments
  • context - Directory context used by the Dockerfile.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn default_args(&self) -> Result<Vec<String>>

Retrieves default arguments for future commands.

source

pub fn directory(&self, path: impl Into<String>) -> Directory

Retrieves a directory at the given path. Mounts are included.

Arguments
  • path - The path of the directory to retrieve (e.g., “./src”).
source

pub async fn endpoint(&self) -> Result<String>

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.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn endpoint_opts<'a>( &self, opts: ContainerEndpointOpts<'a> ) -> Result<String>

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.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn entrypoint(&self) -> Result<Vec<String>>

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

source

pub async fn env_variable(&self, name: impl Into<String>) -> Result<String>

Retrieves the value of the specified environment variable.

Arguments
  • name - The name of the environment variable to retrieve (e.g., “PATH”).
source

pub fn env_variables(&self) -> Vec<EnvVariable>

Retrieves the list of environment variables passed to commands.

source

pub fn exec(&self) -> Container

Retrieves this container after executing the specified command inside it.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn exec_opts<'a>(&self, opts: ContainerExecOpts<'a>) -> Container

Retrieves this container after executing the specified command inside it.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn exit_code(&self) -> Result<isize>

Exit code of the last executed command. Zero means success. Errors if no command has been executed.

source

pub async fn export(&self, path: impl Into<String>) -> Result<bool>

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.

Arguments
  • path - Host’s destination path (e.g., “./tarball”). Path can be relative to the engine’s workdir or absolute.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn export_opts( &self, path: impl Into<String>, opts: ContainerExportOpts ) -> Result<bool>

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.

Arguments
  • path - Host’s destination path (e.g., “./tarball”). Path can be relative to the engine’s workdir or absolute.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn exposed_ports(&self) -> Vec<Port>

Retrieves the list of exposed ports. Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

source

pub fn file(&self, path: impl Into<String>) -> File

Retrieves a file at the given path. Mounts are included.

Arguments
  • path - The path of the file to retrieve (e.g., “./README.md”).
source

pub fn from(&self, address: impl Into<String>) -> Container

Initializes this container from a pulled base image.

Arguments
  • address - Image’s address from its registry.

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

source

pub fn fs(&self) -> Directory

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

source

pub async fn hostname(&self) -> Result<String>

Retrieves a hostname which can be used by clients to reach this container. Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

source

pub async fn id(&self) -> Result<ContainerId>

A unique identifier for this container.

source

pub async fn image_ref(&self) -> Result<String>

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

source

pub async fn label(&self, name: impl Into<String>) -> Result<String>

Retrieves the value of the specified label.

source

pub fn labels(&self) -> Vec<Label>

Retrieves the list of labels passed to container.

source

pub async fn mounts(&self) -> Result<Vec<String>>

Retrieves the list of paths where a directory is mounted.

source

pub fn pipeline(&self, name: impl Into<String>) -> Container

Creates a named sub-pipeline

Arguments
  • name - Pipeline name.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn pipeline_opts<'a>( &self, name: impl Into<String>, opts: ContainerPipelineOpts<'a> ) -> Container

Creates a named sub-pipeline

Arguments
  • name - Pipeline name.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn platform(&self) -> Result<Platform>

The platform this container executes and publishes as.

source

pub async fn publish(&self, address: impl Into<String>) -> Result<String>

Publishes this container as a new image to the specified address. Publish returns a fully qualified ref. It can also publish platform variants.

Arguments
  • address - Registry’s address to publish the image to.

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

  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub async fn publish_opts( &self, address: impl Into<String>, opts: ContainerPublishOpts ) -> Result<String>

Publishes this container as a new image to the specified address. Publish returns a fully qualified ref. It can also publish platform variants.

Arguments
  • address - Registry’s address to publish the image to.

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

  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn rootfs(&self) -> Directory

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

source

pub async fn stderr(&self) -> Result<String>

The error stream of the last executed command. Errors if no command has been executed.

source

pub async fn stdout(&self) -> Result<String>

The output stream of the last executed command. Errors if no command has been executed.

source

pub async fn user(&self) -> Result<String>

Retrieves the user to be set for all commands.

source

pub fn with_default_args(&self) -> Container

Configures default arguments for future commands.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_default_args_opts<'a>( &self, opts: ContainerWithDefaultArgsOpts<'a> ) -> Container

Configures default arguments for future commands.

Arguments
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_directory( &self, path: impl Into<String>, directory: DirectoryId ) -> Container

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

Arguments
  • path - Location of the written directory (e.g., “/tmp/directory”).
  • directory - Identifier of the directory to write
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_directory_opts<'a>( &self, path: impl Into<String>, directory: DirectoryId, opts: ContainerWithDirectoryOpts<'a> ) -> Container

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

Arguments
  • path - Location of the written directory (e.g., “/tmp/directory”).
  • directory - Identifier of the directory to write
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_entrypoint(&self, args: Vec<impl Into<String>>) -> Container

Retrieves this container but with a different command entrypoint.

Arguments
  • args - Entrypoint to use for future executions (e.g., [“go”, “run”]).
source

pub fn with_env_variable( &self, name: impl Into<String>, value: impl Into<String> ) -> Container

Retrieves this container plus the given environment variable.

Arguments
  • name - The name of the environment variable (e.g., “HOST”).
  • value - The value of the environment variable. (e.g., “localhost”).
source

pub fn with_exec(&self, args: Vec<impl Into<String>>) -> Container

Retrieves this container after executing the specified command inside it.

Arguments
  • args - Command to run instead of the container’s default command (e.g., [“run”, “main.go”]).
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_exec_opts<'a>( &self, args: Vec<impl Into<String>>, opts: ContainerWithExecOpts<'a> ) -> Container

Retrieves this container after executing the specified command inside it.

Arguments
  • args - Command to run instead of the container’s default command (e.g., [“run”, “main.go”]).
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_exposed_port(&self, port: isize) -> Container

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.
Arguments
  • port - Port number to expose
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_exposed_port_opts<'a>( &self, port: isize, opts: ContainerWithExposedPortOpts<'a> ) -> Container

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.
Arguments
  • port - Port number to expose
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_fs(&self, id: DirectoryId) -> Container

Initializes this container from this DirectoryID.

source

pub fn with_file(&self, path: impl Into<String>, source: FileId) -> Container

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

Arguments
  • path - Location of the copied file (e.g., “/tmp/file.txt”).
  • source - Identifier of the file to copy.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_file_opts( &self, path: impl Into<String>, source: FileId, opts: ContainerWithFileOpts ) -> Container

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

Arguments
  • path - Location of the copied file (e.g., “/tmp/file.txt”).
  • source - Identifier of the file to copy.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_label( &self, name: impl Into<String>, value: impl Into<String> ) -> Container

Retrieves this container plus the given label.

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”).
source

pub fn with_mounted_cache( &self, path: impl Into<String>, cache: CacheId ) -> Container

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

Arguments
  • path - Location of the cache directory (e.g., “/cache/node_modules”).
  • cache - Identifier of the cache volume to mount.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_mounted_cache_opts( &self, path: impl Into<String>, cache: CacheId, opts: ContainerWithMountedCacheOpts ) -> Container

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

Arguments
  • path - Location of the cache directory (e.g., “/cache/node_modules”).
  • cache - Identifier of the cache volume to mount.
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_mounted_directory( &self, path: impl Into<String>, source: DirectoryId ) -> Container

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

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

pub fn with_mounted_file( &self, path: impl Into<String>, source: FileId ) -> Container

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

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

pub fn with_mounted_secret( &self, path: impl Into<String>, source: SecretId ) -> Container

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

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

pub fn with_mounted_temp(&self, path: impl Into<String>) -> Container

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

Arguments
  • path - Location of the temporary directory (e.g., “/tmp/temp_dir”).
source

pub fn with_new_file(&self, path: impl Into<String>) -> Container

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

Arguments
  • path - Location of the written file (e.g., “/tmp/file.txt”).
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_new_file_opts<'a>( &self, path: impl Into<String>, opts: ContainerWithNewFileOpts<'a> ) -> Container

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

Arguments
  • path - Location of the written file (e.g., “/tmp/file.txt”).
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn with_registry_auth( &self, address: impl Into<String>, username: impl Into<String>, secret: SecretId ) -> Container

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

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

pub fn with_rootfs(&self, id: DirectoryId) -> Container

Initializes this container from this DirectoryID.

source

pub fn with_secret_variable( &self, name: impl Into<String>, secret: SecretId ) -> Container

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

Arguments
  • name - The name of the secret variable (e.g., “API_SECRET”).
  • secret - The identifier of the secret value.
source

pub fn with_service_binding( &self, alias: impl Into<String>, service: ContainerId ) -> Container

Establish a runtime dependency on a service. The service will be started automatically when needed and detached when it is no longer needed. 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.

Arguments
  • alias - A name that can be used to reach the service from the container
  • service - Identifier of the service container
source

pub fn with_unix_socket( &self, path: impl Into<String>, source: SocketId ) -> Container

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

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

pub fn with_user(&self, name: impl Into<String>) -> Container

Retrieves this container with a different command user.

Arguments
  • name - The user to set (e.g., “root”).
source

pub fn with_workdir(&self, path: impl Into<String>) -> Container

Retrieves this container with a different working directory.

Arguments
  • path - The path to set as the working directory (e.g., “/app”).
source

pub fn without_env_variable(&self, name: impl Into<String>) -> Container

Retrieves this container minus the given environment variable.

Arguments
  • name - The name of the environment variable (e.g., “HOST”).
source

pub fn without_exposed_port(&self, port: isize) -> Container

Unexpose a previously exposed port. Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

Arguments
  • port - Port number to unexpose
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn without_exposed_port_opts( &self, port: isize, opts: ContainerWithoutExposedPortOpts ) -> Container

Unexpose a previously exposed port. Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.

Arguments
  • port - Port number to unexpose
  • opt - optional argument, see inner type for documentation, use _opts to use
source

pub fn without_label(&self, name: impl Into<String>) -> Container

Retrieves this container minus the given environment label.

Arguments
  • name - The name of the label to remove (e.g., “org.opencontainers.artifact.created”).
source

pub fn without_mount(&self, path: impl Into<String>) -> Container

Retrieves this container after unmounting everything at the given path.

Arguments
  • path - Location of the cache directory (e.g., “/cache/node_modules”).
source

pub fn without_registry_auth(&self, address: impl Into<String>) -> Container

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

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

pub fn without_unix_socket(&self, path: impl Into<String>) -> Container

Retrieves this container with a previously added Unix socket removed.

Arguments
  • path - Location of the socket to remove (e.g., “/tmp/socket”).
source

pub async fn workdir(&self) -> Result<String>

Retrieves the working directory for all commands.

Trait Implementations§

source§

impl Clone for Container

source§

fn clone(&self) -> Container

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Container

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more