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: ConnectParamsImplementations§
source§impl Container
impl Container
sourcepub fn build(&self, context: DirectoryId) -> Container
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
sourcepub fn build_opts<'a>(
&self,
context: DirectoryId,
opts: ContainerBuildOpts<'a>
) -> Container
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
sourcepub async fn default_args(&self) -> Result<Vec<String>>
pub async fn default_args(&self) -> Result<Vec<String>>
Retrieves default arguments for future commands.
sourcepub fn directory(&self, path: impl Into<String>) -> Directory
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”).
sourcepub async fn endpoint(&self) -> Result<String>
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
sourcepub async fn endpoint_opts<'a>(
&self,
opts: ContainerEndpointOpts<'a>
) -> Result<String>
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
sourcepub async fn entrypoint(&self) -> Result<Vec<String>>
pub async fn entrypoint(&self) -> Result<Vec<String>>
Retrieves entrypoint to be prepended to the arguments of all commands.
sourcepub async fn env_variable(&self, name: impl Into<String>) -> Result<String>
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”).
sourcepub fn env_variables(&self) -> Vec<EnvVariable>
pub fn env_variables(&self) -> Vec<EnvVariable>
Retrieves the list of environment variables passed to commands.
sourcepub fn exec(&self) -> Container
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
sourcepub fn exec_opts<'a>(&self, opts: ContainerExecOpts<'a>) -> Container
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
sourcepub async fn exit_code(&self) -> Result<isize>
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.
sourcepub async fn export(&self, path: impl Into<String>) -> Result<bool>
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
sourcepub async fn export_opts(
&self,
path: impl Into<String>,
opts: ContainerExportOpts
) -> Result<bool>
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
sourcepub fn exposed_ports(&self) -> Vec<Port>
pub fn exposed_ports(&self) -> Vec<Port>
Retrieves the list of exposed ports. Currently experimental; set _EXPERIMENTAL_DAGGER_SERVICES_DNS=0 to disable.
sourcepub fn file(&self, path: impl Into<String>) -> File
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”).
sourcepub fn from(&self, address: impl Into<String>) -> Container
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”).
sourcepub fn fs(&self) -> Directory
pub fn fs(&self) -> Directory
Retrieves this container’s root filesystem. Mounts are not included.
sourcepub async fn hostname(&self) -> Result<String>
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.
sourcepub async fn id(&self) -> Result<ContainerId>
pub async fn id(&self) -> Result<ContainerId>
A unique identifier for this container.
sourcepub async fn image_ref(&self) -> Result<String>
pub async fn image_ref(&self) -> Result<String>
The unique image reference which can only be retrieved immediately after the ‘Container.From’ call.
sourcepub async fn label(&self, name: impl Into<String>) -> Result<String>
pub async fn label(&self, name: impl Into<String>) -> Result<String>
Retrieves the value of the specified label.
sourcepub async fn mounts(&self) -> Result<Vec<String>>
pub async fn mounts(&self) -> Result<Vec<String>>
Retrieves the list of paths where a directory is mounted.
sourcepub fn pipeline(&self, name: impl Into<String>) -> Container
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
sourcepub fn pipeline_opts<'a>(
&self,
name: impl Into<String>,
opts: ContainerPipelineOpts<'a>
) -> Container
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
sourcepub async fn platform(&self) -> Result<Platform>
pub async fn platform(&self) -> Result<Platform>
The platform this container executes and publishes as.
sourcepub async fn publish(&self, address: impl Into<String>) -> Result<String>
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
sourcepub async fn publish_opts(
&self,
address: impl Into<String>,
opts: ContainerPublishOpts
) -> Result<String>
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
sourcepub fn rootfs(&self) -> Directory
pub fn rootfs(&self) -> Directory
Retrieves this container’s root filesystem. Mounts are not included.
sourcepub async fn stderr(&self) -> Result<String>
pub async fn stderr(&self) -> Result<String>
The error stream of the last executed command. Errors if no command has been executed.
sourcepub async fn stdout(&self) -> Result<String>
pub async fn stdout(&self) -> Result<String>
The output stream of the last executed command. Errors if no command has been executed.
sourcepub fn with_default_args(&self) -> Container
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
sourcepub fn with_default_args_opts<'a>(
&self,
opts: ContainerWithDefaultArgsOpts<'a>
) -> Container
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
sourcepub fn with_directory(
&self,
path: impl Into<String>,
directory: DirectoryId
) -> Container
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 writeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn with_directory_opts<'a>(
&self,
path: impl Into<String>,
directory: DirectoryId,
opts: ContainerWithDirectoryOpts<'a>
) -> Container
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 writeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn with_entrypoint(&self, args: Vec<impl Into<String>>) -> Container
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”]).
sourcepub fn with_env_variable(
&self,
name: impl Into<String>,
value: impl Into<String>
) -> Container
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”).
sourcepub fn with_exec(&self, args: Vec<impl Into<String>>) -> Container
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
sourcepub fn with_exec_opts<'a>(
&self,
args: Vec<impl Into<String>>,
opts: ContainerWithExecOpts<'a>
) -> Container
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
sourcepub fn with_exposed_port(&self, port: isize) -> Container
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 exposeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn with_exposed_port_opts<'a>(
&self,
port: isize,
opts: ContainerWithExposedPortOpts<'a>
) -> Container
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 exposeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn with_fs(&self, id: DirectoryId) -> Container
pub fn with_fs(&self, id: DirectoryId) -> Container
Initializes this container from this DirectoryID.
sourcepub fn with_file(&self, path: impl Into<String>, source: FileId) -> Container
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
sourcepub fn with_file_opts(
&self,
path: impl Into<String>,
source: FileId,
opts: ContainerWithFileOpts
) -> Container
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
sourcepub fn with_label(
&self,
name: impl Into<String>,
value: impl Into<String>
) -> Container
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”).
sourcepub fn with_mounted_cache(
&self,
path: impl Into<String>,
cache: CacheId
) -> Container
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
sourcepub fn with_mounted_cache_opts(
&self,
path: impl Into<String>,
cache: CacheId,
opts: ContainerWithMountedCacheOpts
) -> Container
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
sourcepub fn with_mounted_directory(
&self,
path: impl Into<String>,
source: DirectoryId
) -> Container
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.
sourcepub fn with_mounted_file(
&self,
path: impl Into<String>,
source: FileId
) -> Container
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.
sourcepub fn with_mounted_secret(
&self,
path: impl Into<String>,
source: SecretId
) -> Container
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.
sourcepub fn with_mounted_temp(&self, path: impl Into<String>) -> Container
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”).
sourcepub fn with_new_file(&self, path: impl Into<String>) -> Container
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
sourcepub fn with_new_file_opts<'a>(
&self,
path: impl Into<String>,
opts: ContainerWithNewFileOpts<'a>
) -> Container
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
sourcepub fn with_registry_auth(
&self,
address: impl Into<String>,
username: impl Into<String>,
secret: SecretId
) -> Container
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.
sourcepub fn with_rootfs(&self, id: DirectoryId) -> Container
pub fn with_rootfs(&self, id: DirectoryId) -> Container
Initializes this container from this DirectoryID.
sourcepub fn with_secret_variable(
&self,
name: impl Into<String>,
secret: SecretId
) -> Container
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.
sourcepub fn with_service_binding(
&self,
alias: impl Into<String>,
service: ContainerId
) -> Container
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 containerservice- Identifier of the service container
sourcepub fn with_unix_socket(
&self,
path: impl Into<String>,
source: SocketId
) -> Container
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.
sourcepub fn with_user(&self, name: impl Into<String>) -> Container
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”).
sourcepub fn with_workdir(&self, path: impl Into<String>) -> Container
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”).
sourcepub fn without_env_variable(&self, name: impl Into<String>) -> Container
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”).
sourcepub fn without_exposed_port(&self, port: isize) -> Container
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 unexposeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn without_exposed_port_opts(
&self,
port: isize,
opts: ContainerWithoutExposedPortOpts
) -> Container
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 unexposeopt- optional argument, see inner type for documentation, use_opts to use
sourcepub fn without_label(&self, name: impl Into<String>) -> Container
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”).
sourcepub fn without_mount(&self, path: impl Into<String>) -> Container
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”).
sourcepub fn without_registry_auth(&self, address: impl Into<String>) -> Container
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).