# `Dagger.Container`
[🔗](https://github.com/dagger/dagger/blob/v0.20.5/sdk/elixir/lib/dagger/gen/container.ex#L2)

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

# `t`

```elixir
@type t() :: %Dagger.Container{client: term(), query_builder: term()}
```

# `as_service`

```elixir
@spec as_service(t(),
  args: [String.t()],
  use_entrypoint: boolean() | nil,
  experimental_privileged_nesting: boolean() | nil,
  insecure_root_capabilities: boolean() | nil,
  expand: boolean() | nil,
  no_init: boolean() | nil
) :: Dagger.Service.t()
```

Turn the container into a Service.

Be sure to set any exposed ports before this conversion.

# `as_tarball`

```elixir
@spec as_tarball(t(),
  platform_variants: [Dagger.ContainerID.t()],
  forced_compression: Dagger.ImageLayerCompression.t() | nil,
  media_types: Dagger.ImageMediaTypes.t() | nil
) :: Dagger.File.t()
```

Package the container state as an OCI image, and return it as a tar archive

# `combined_output`

```elixir
@spec combined_output(t()) :: {:ok, String.t()} | {:error, term()}
```

The combined buffered standard output and standard error stream of the last executed command

Returns an error if no command was executed

# `default_args`

```elixir
@spec default_args(t()) :: {:ok, [String.t()]} | {:error, term()}
```

Return the container's default arguments.

# `directory`

```elixir
@spec directory(t(), String.t(), [{:expand, boolean() | nil}]) :: Dagger.Directory.t()
```

Retrieve a directory from the container's root filesystem

Mounts are included.

# `entrypoint`

```elixir
@spec entrypoint(t()) :: {:ok, [String.t()]} | {:error, term()}
```

Return the container's OCI entrypoint.

# `env_variable`

```elixir
@spec env_variable(t(), String.t()) :: {:ok, String.t() | nil} | {:error, term()}
```

Retrieves the value of the specified environment variable.

# `env_variables`

```elixir
@spec env_variables(t()) :: {:ok, [Dagger.EnvVariable.t()]} | {:error, term()}
```

Retrieves the list of environment variables passed to commands.

# `exists`

```elixir
@spec exists(t(), String.t(),
  expected_type: Dagger.ExistsType.t() | nil,
  do_not_follow_symlinks: boolean() | nil
) :: {:ok, boolean()} | {:error, term()}
```

check if a file or directory exists

# `exit_code`

```elixir
@spec exit_code(t()) :: {:ok, integer()} | {:error, term()}
```

The exit code of the last executed command

Returns an error if no command was executed

# `experimental_with_all_gpus`

```elixir
@spec experimental_with_all_gpus(t()) :: t()
```

EXPERIMENTAL API! Subject to change/removal at any time.

Configures all available GPUs on the host to be accessible to this container.

This currently works for Nvidia devices only.

# `experimental_with_gpu`

```elixir
@spec experimental_with_gpu(t(), [String.t()]) :: t()
```

EXPERIMENTAL API! Subject to change/removal at any time.

Configures the provided list of devices to be accessible to this container.

This currently works for Nvidia devices only.

# `export`

```elixir
@spec export(t(), String.t(),
  platform_variants: [Dagger.ContainerID.t()],
  forced_compression: Dagger.ImageLayerCompression.t() | nil,
  media_types: Dagger.ImageMediaTypes.t() | nil,
  expand: boolean() | nil
) :: {:ok, String.t()} | {:error, term()}
```

Writes the container as an OCI tarball to the destination file path on the host.

It can also export platform variants.

# `export_image`

```elixir
@spec export_image(t(), String.t(),
  platform_variants: [Dagger.ContainerID.t()],
  forced_compression: Dagger.ImageLayerCompression.t() | nil,
  media_types: Dagger.ImageMediaTypes.t() | nil
) :: :ok | {:error, term()}
```

Exports the container as an image to the host's container image store.

# `exposed_ports`

```elixir
@spec exposed_ports(t()) :: {:ok, [Dagger.Port.t()]} | {:error, term()}
```

Retrieves the list of exposed ports.

This includes ports already exposed by the image, even if not explicitly added with dagger.

# `file`

```elixir
@spec file(t(), String.t(), [{:expand, boolean() | nil}]) :: Dagger.File.t()
```

Retrieves a file at the given path.

Mounts are included.

# `from`

```elixir
@spec from(t(), String.t()) :: t()
```

Download a container image, and apply it to the container state. All previous state will be lost.

# `id`

```elixir
@spec id(t()) :: {:ok, Dagger.ContainerID.t()} | {:error, term()}
```

A unique identifier for this Container.

# `image_ref`

```elixir
@spec image_ref(t()) :: {:ok, String.t()} | {:error, term()}
```

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

# `import`

```elixir
@spec import(t(), Dagger.File.t(), [{:tag, String.t() | nil}]) :: t()
```

Reads the container from an OCI tarball.

# `label`

```elixir
@spec label(t(), String.t()) :: {:ok, String.t() | nil} | {:error, term()}
```

Retrieves the value of the specified label.

# `labels`

```elixir
@spec labels(t()) :: {:ok, [Dagger.Label.t()]} | {:error, term()}
```

Retrieves the list of labels passed to container.

# `mounts`

```elixir
@spec mounts(t()) :: {:ok, [String.t()]} | {:error, term()}
```

Retrieves the list of paths where a directory is mounted.

# `platform`

```elixir
@spec platform(t()) :: {:ok, Dagger.Platform.t()} | {:error, term()}
```

The platform this container executes and publishes as.

# `publish`

```elixir
@spec publish(t(), String.t(),
  platform_variants: [Dagger.ContainerID.t()],
  forced_compression: Dagger.ImageLayerCompression.t() | nil,
  media_types: Dagger.ImageMediaTypes.t() | nil
) :: {:ok, String.t()} | {:error, term()}
```

Package the container state as an OCI image, and publish it to a registry

Returns the fully qualified address of the published image, with digest

# `rootfs`

```elixir
@spec rootfs(t()) :: Dagger.Directory.t()
```

Return a snapshot of the container's root filesystem. The snapshot can be modified then written back using withRootfs. Use that method for filesystem modifications.

# `stderr`

```elixir
@spec stderr(t()) :: {:ok, String.t()} | {:error, term()}
```

The buffered standard error stream of the last executed command

Returns an error if no command was executed

# `stdout`

```elixir
@spec stdout(t()) :: {:ok, String.t()} | {:error, term()}
```

The buffered standard output stream of the last executed command

Returns an error if no command was executed

# `sync`

```elixir
@spec sync(t()) :: {:ok, t()} | {:error, term()}
```

Forces evaluation of the pipeline in the engine.

It doesn't run the default command if no exec has been set.

# `terminal`

```elixir
@spec terminal(t(),
  cmd: [String.t()],
  experimental_privileged_nesting: boolean() | nil,
  insecure_root_capabilities: boolean() | nil
) :: t()
```

Opens an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default).

# `up`

```elixir
@spec up(t(),
  random: boolean() | nil,
  ports: [Dagger.PortForward.t()],
  args: [String.t()],
  use_entrypoint: boolean() | nil,
  experimental_privileged_nesting: boolean() | nil,
  insecure_root_capabilities: boolean() | nil,
  expand: boolean() | nil,
  no_init: boolean() | nil
) :: :ok | {:error, term()}
```

Starts a Service and creates a tunnel that forwards traffic from the caller's network to that service.

Be sure to set any exposed ports before calling this api.

# `user`

```elixir
@spec user(t()) :: {:ok, String.t()} | {:error, term()}
```

Retrieves the user to be set for all commands.

# `with_annotation`

```elixir
@spec with_annotation(t(), String.t(), String.t()) :: t()
```

Retrieves this container plus the given OCI anotation.

# `with_default_args`

```elixir
@spec with_default_args(t(), [String.t()]) :: t()
```

Configures default arguments for future commands. Like CMD in Dockerfile.

# `with_default_terminal_cmd`

```elixir
@spec with_default_terminal_cmd(t(), [String.t()],
  experimental_privileged_nesting: boolean() | nil,
  insecure_root_capabilities: boolean() | nil
) :: t()
```

Set the default command to invoke for the container's terminal API.

# `with_directory`

```elixir
@spec with_directory(t(), String.t(), Dagger.Directory.t(),
  exclude: [String.t()],
  include: [String.t()],
  gitignore: boolean() | nil,
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

Return a new container snapshot, with a directory added to its filesystem

# `with_entrypoint`

```elixir
@spec with_entrypoint(t(), [String.t()], [{:keep_default_args, boolean() | nil}]) ::
  t()
```

Set an OCI-style entrypoint. It will be included in the container's OCI configuration. Note, withExec ignores the entrypoint by default.

# `with_env_file_variables`

```elixir
@spec with_env_file_variables(t(), Dagger.EnvFile.t()) :: t()
```

Export environment variables from an env-file to the container.

# `with_env_variable`

```elixir
@spec with_env_variable(t(), String.t(), String.t(), [{:expand, boolean() | nil}]) ::
  t()
```

Set a new environment variable in the container.

# `with_error`

```elixir
@spec with_error(t(), String.t()) :: t()
```

Raise an error.

# `with_exec`

```elixir
@spec with_exec(t(), [String.t()],
  use_entrypoint: boolean() | nil,
  stdin: String.t() | nil,
  redirect_stdin: String.t() | nil,
  redirect_stdout: String.t() | nil,
  redirect_stderr: String.t() | nil,
  expect: Dagger.ReturnType.t() | nil,
  experimental_privileged_nesting: boolean() | nil,
  insecure_root_capabilities: boolean() | nil,
  expand: boolean() | nil,
  no_init: boolean() | nil
) :: t()
```

Execute a command in the container, and return a new snapshot of the container state after execution.

# `with_exposed_port`

```elixir
@spec with_exposed_port(t(), integer(),
  protocol: Dagger.NetworkProtocol.t() | nil,
  description: String.t() | nil,
  experimental_skip_healthcheck: boolean() | nil
) :: t()
```

Expose a network port. Like EXPOSE in Dockerfile (but with healthcheck support)

Exposed ports serve two purposes:

- For health checks and introspection, when running services

- For setting the EXPOSE OCI field when publishing the container

# `with_file`

```elixir
@spec with_file(t(), String.t(), Dagger.File.t(),
  permissions: integer() | nil,
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

Return a container snapshot with a file added

# `with_files`

```elixir
@spec with_files(t(), String.t(), [Dagger.FileID.t()],
  permissions: integer() | nil,
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_label`

```elixir
@spec with_label(t(), String.t(), String.t()) :: t()
```

Retrieves this container plus the given label.

# `with_mounted_cache`

```elixir
@spec with_mounted_cache(t(), String.t(), Dagger.CacheVolume.t(),
  source: Dagger.DirectoryID.t() | nil,
  sharing: Dagger.CacheSharingMode.t() | nil,
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_mounted_directory`

```elixir
@spec with_mounted_directory(t(), String.t(), Dagger.Directory.t(),
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_mounted_file`

```elixir
@spec with_mounted_file(t(), String.t(), Dagger.File.t(),
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_mounted_secret`

```elixir
@spec with_mounted_secret(t(), String.t(), Dagger.Secret.t(),
  owner: String.t() | nil,
  mode: integer() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_mounted_temp`

```elixir
@spec with_mounted_temp(t(), String.t(),
  size: integer() | nil,
  expand: boolean() | nil
) :: t()
```

Retrieves this container plus a temporary directory mounted at the given path. Any writes will be ephemeral to a single withExec call; they will not be persisted to subsequent withExecs.

# `with_new_file`

```elixir
@spec with_new_file(t(), String.t(), String.t(),
  permissions: integer() | nil,
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

Return a new container snapshot, with a file added to its filesystem with text content

# `with_registry_auth`

```elixir
@spec with_registry_auth(t(), String.t(), String.t(), Dagger.Secret.t()) :: t()
```

Attach credentials for future publishing to a registry. Use in combination with publish

# `with_rootfs`

```elixir
@spec with_rootfs(t(), Dagger.Directory.t()) :: t()
```

Change the container's root filesystem. The previous root filesystem will be lost.

# `with_secret_variable`

```elixir
@spec with_secret_variable(t(), String.t(), Dagger.Secret.t()) :: t()
```

Set a new environment variable, using a secret value

# `with_service_binding`

```elixir
@spec with_service_binding(t(), String.t(), Dagger.Service.t()) :: t()
```

Establish a runtime dependency from a container to a network 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.

# `with_symlink`

```elixir
@spec with_symlink(t(), String.t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Return a snapshot with a symlink

# `with_unix_socket`

```elixir
@spec with_unix_socket(t(), String.t(), Dagger.Socket.t(),
  owner: String.t() | nil,
  expand: boolean() | nil
) :: t()
```

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

# `with_user`

```elixir
@spec with_user(t(), String.t()) :: t()
```

Retrieves this container with a different command user.

# `with_workdir`

```elixir
@spec with_workdir(t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Change the container's working directory. Like WORKDIR in Dockerfile.

# `without_annotation`

```elixir
@spec without_annotation(t(), String.t()) :: t()
```

Retrieves this container minus the given OCI annotation.

# `without_default_args`

```elixir
@spec without_default_args(t()) :: t()
```

Remove the container's default arguments.

# `without_directory`

```elixir
@spec without_directory(t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Return a new container snapshot, with a directory removed from its filesystem

# `without_entrypoint`

```elixir
@spec without_entrypoint(t(), [{:keep_default_args, boolean() | nil}]) :: t()
```

Reset the container's OCI entrypoint.

# `without_env_variable`

```elixir
@spec without_env_variable(t(), String.t()) :: t()
```

Retrieves this container minus the given environment variable.

# `without_exposed_port`

```elixir
@spec without_exposed_port(t(), integer(), [
  {:protocol, Dagger.NetworkProtocol.t() | nil}
]) :: t()
```

Unexpose a previously exposed port.

# `without_file`

```elixir
@spec without_file(t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Retrieves this container with the file at the given path removed.

# `without_files`

```elixir
@spec without_files(t(), [String.t()], [{:expand, boolean() | nil}]) :: t()
```

Return a new container spanshot with specified files removed

# `without_label`

```elixir
@spec without_label(t(), String.t()) :: t()
```

Retrieves this container minus the given environment label.

# `without_mount`

```elixir
@spec without_mount(t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Retrieves this container after unmounting everything at the given path.

# `without_registry_auth`

```elixir
@spec without_registry_auth(t(), String.t()) :: t()
```

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

# `without_secret_variable`

```elixir
@spec without_secret_variable(t(), String.t()) :: t()
```

Retrieves this container minus the given environment variable containing the secret.

# `without_unix_socket`

```elixir
@spec without_unix_socket(t(), String.t(), [{:expand, boolean() | nil}]) :: t()
```

Retrieves this container with a previously added Unix socket removed.

# `without_user`

```elixir
@spec without_user(t()) :: t()
```

Retrieves this container with an unset command user.

Should default to root.

# `without_workdir`

```elixir
@spec without_workdir(t()) :: t()
```

Unset the container's working directory.

Should default to "/".

# `workdir`

```elixir
@spec workdir(t()) :: {:ok, String.t()} | {:error, term()}
```

Retrieves the working directory for all commands.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
