class Container extends AbstractObject implements IdAble

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

Properties

$lastQuery from  AbstractObject

Methods

__construct(AbstractClient $client, QueryBuilderChain $queryBuilderChain)

No description

null|array|string|int|float|bool
queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)

No description

asService(array|null $args = null, bool|null $useEntrypoint = false, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

Turn the container into a Service.

asTarball(array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)

Returns a File representing the container serialized to a tarball.

build(Directory $context, string|null $dockerfile = 'Dockerfile', string|null $target = '', array|null $buildArgs = null, array|null $secrets = null)

Initializes this container from a Dockerfile build.

array
defaultArgs()

Retrieves default arguments for future commands.

directory(string $path, bool|null $expand = false)

Retrieves a directory at the given path.

array
entrypoint()

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

string
envVariable(string $name)

Retrieves the value of the specified environment variable.

array
envVariables()

Retrieves the list of environment variables passed to commands.

int
exitCode()

The exit code of the last executed command.

experimentalWithAllGPUs()

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

experimentalWithGPU(array $devices)

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

string
export(string $path, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null, bool|null $expand = false)

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

array
exposedPorts()

Retrieves the list of exposed ports.

file(string $path, bool|null $expand = false)

Retrieves a file at the given path.

from(string $address)

Initializes this container from a pulled base image.

id()

A unique identifier for this Container.

string
imageRef()

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

import(File $source, string|null $tag = '')

Reads the container from an OCI tarball.

string
label(string $name)

Retrieves the value of the specified label.

array
labels()

Retrieves the list of labels passed to container.

array
mounts()

Retrieves the list of paths where a directory is mounted.

platform()

The platform this container executes and publishes as.

string
publish(string $address, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)

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

rootfs()

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

string
stderr()

The error stream of the last executed command.

string
stdout()

The output stream of the last executed command.

sync()

Forces evaluation of the pipeline in the engine.

terminal(array|null $cmd = null, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false)

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

void
up(array|null $ports = null, bool|null $random = false, array|null $args = null, bool|null $useEntrypoint = false, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

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

string
user()

Retrieves the user to be set for all commands.

withAnnotation(string $name, string $value)

Retrieves this container plus the given OCI anotation.

withDefaultArgs(array $args)

Configures default arguments for future commands.

withDefaultTerminalCmd(array $args, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false)

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

withDirectory(string $path, Directory $directory, array|null $exclude = null, array|null $include = null, string|null $owner = '', bool|null $expand = false)

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

withEntrypoint(array $args, bool|null $keepDefaultArgs = false)

Retrieves this container but with a different command entrypoint.

withEnvVariable(string $name, string $value, bool|null $expand = false)

Retrieves this container plus the given environment variable.

withExec(array $args, bool|null $useEntrypoint = false, string|null $stdin = '', string|null $redirectStdout = '', string|null $redirectStderr = '', ReturnType|null $expect = null, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

Retrieves this container after executing the specified command inside it.

withExposedPort(int $port, NetworkProtocol|null $protocol = null, string|null $description = null, bool|null $experimentalSkipHealthcheck = false)

Expose a network port.

withFile(string $path, File $source, int|null $permissions = null, string|null $owner = '', bool|null $expand = false)

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

withFiles(string $path, array $sources, int|null $permissions = null, string|null $owner = '', bool|null $expand = false)

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

withLabel(string $name, string $value)

Retrieves this container plus the given label.

withMountedCache(string $path, CacheVolume $cache, Directory|null $source = null, CacheSharingMode|null $sharing = null, string|null $owner = '', bool|null $expand = false)

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

withMountedDirectory(string $path, Directory $source, string|null $owner = '', bool|null $expand = false)

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

withMountedFile(string $path, File $source, string|null $owner = '', bool|null $expand = false)

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

withMountedSecret(string $path, Secret $source, string|null $owner = '', int|null $mode = 256, bool|null $expand = false)

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

withMountedTemp(string $path, int|null $size = null, bool|null $expand = false)

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.

withNewFile(string $path, string $contents, int|null $permissions = 420, string|null $owner = '', bool|null $expand = false)

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

withRegistryAuth(string $address, string $username, Secret $secret)

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

withRootfs(Directory $directory)

Retrieves the container with the given directory mounted to /.

withSecretVariable(string $name, Secret $secret)

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

withServiceBinding(string $alias, Service $service)

Establish a runtime dependency on a service.

withUnixSocket(string $path, Socket $source, string|null $owner = '', bool|null $expand = false)

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

withUser(string $name)

Retrieves this container with a different command user.

withWorkdir(string $path, bool|null $expand = false)

Retrieves this container with a different working directory.

withoutAnnotation(string $name)

Retrieves this container minus the given OCI annotation.

withoutDefaultArgs()

Retrieves this container with unset default arguments for future commands.

withoutDirectory(string $path, bool|null $expand = false)

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

withoutEntrypoint(bool|null $keepDefaultArgs = false)

Retrieves this container with an unset command entrypoint.

withoutEnvVariable(string $name)

Retrieves this container minus the given environment variable.

withoutExposedPort(int $port, NetworkProtocol|null $protocol = null)

Unexpose a previously exposed port.

withoutFile(string $path, bool|null $expand = false)

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

withoutFiles(array $paths, bool|null $expand = false)

Retrieves this container with the files at the given paths removed.

withoutLabel(string $name)

Retrieves this container minus the given environment label.

withoutMount(string $path, bool|null $expand = false)

Retrieves this container after unmounting everything at the given path.

withoutRegistryAuth(string $address)

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

withoutSecretVariable(string $name)

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

withoutUnixSocket(string $path, bool|null $expand = false)

Retrieves this container with a previously added Unix socket removed.

withoutUser()

Retrieves this container with an unset command user.

withoutWorkdir()

Retrieves this container with an unset working directory.

string
workdir()

Retrieves the working directory for all commands.

Details

in AbstractObject at line 13
__construct(AbstractClient $client, QueryBuilderChain $queryBuilderChain)

No description

Parameters

AbstractClient $client
QueryBuilderChain $queryBuilderChain

in AbstractObject at line 19
protected null|array|string|int|float|bool queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)

No description

Parameters

QueryBuilder $leafQueryBuilder
string $leafKey

Return Value

null|array|string|int|float|bool

at line 21
Service asService(array|null $args = null, bool|null $useEntrypoint = false, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

Turn the container into a Service.

Be sure to set any exposed ports before this conversion.

Parameters

array|null $args
bool|null $useEntrypoint
bool|null $experimentalPrivilegedNesting
bool|null $insecureRootCapabilities
bool|null $expand
bool|null $noInit

Return Value

Service

at line 54
File asTarball(array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)

Returns a File representing the container serialized to a tarball.

Parameters

array|null $platformVariants
ImageLayerCompression|null $forcedCompression
ImageMediaTypes|null $mediaTypes

Return Value

File

at line 75
Container build(Directory $context, string|null $dockerfile = 'Dockerfile', string|null $target = '', array|null $buildArgs = null, array|null $secrets = null)

Initializes this container from a Dockerfile build.

Parameters

Directory $context
string|null $dockerfile
string|null $target
array|null $buildArgs
array|null $secrets

Return Value

Container

at line 102
array defaultArgs()

Retrieves default arguments for future commands.

Return Value

array

at line 113
Directory directory(string $path, bool|null $expand = false)

Retrieves a directory at the given path.

Mounts are included.

Parameters

string $path
bool|null $expand

Return Value

Directory

at line 126
array entrypoint()

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

Return Value

array

at line 135
string envVariable(string $name)

Retrieves the value of the specified environment variable.

Parameters

string $name

Return Value

string

at line 145
array envVariables()

Retrieves the list of environment variables passed to commands.

Return Value

array

at line 156
int exitCode()

The exit code of the last executed command.

Returns an error if no command was set.

Return Value

int

at line 169
Container experimentalWithAllGPUs()

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.

Return Value

Container

at line 182
Container experimentalWithGPU(array $devices)

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.

Parameters

array $devices

Return Value

Container

at line 194
string export(string $path, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null, bool|null $expand = false)

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

It can also export platform variants.

Parameters

string $path
array|null $platformVariants
ImageLayerCompression|null $forcedCompression
ImageMediaTypes|null $mediaTypes
bool|null $expand

Return Value

string

at line 223
array exposedPorts()

Retrieves the list of exposed ports.

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

Return Value

array

at line 234
File file(string $path, bool|null $expand = false)

Retrieves a file at the given path.

Mounts are included.

Parameters

string $path
bool|null $expand

Return Value

File

at line 247
Container from(string $address)

Initializes this container from a pulled base image.

Parameters

string $address

Return Value

Container

at line 257
AbstractId id()

A unique identifier for this Container.

Return Value

AbstractId

at line 266
string imageRef()

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

Return Value

string

at line 275
Container import(File $source, string|null $tag = '')

Reads the container from an OCI tarball.

Parameters

File $source
string|null $tag

Return Value

Container

at line 288
string label(string $name)

Retrieves the value of the specified label.

Parameters

string $name

Return Value

string

at line 298
array labels()

Retrieves the list of labels passed to container.

Return Value

array

at line 307
array mounts()

Retrieves the list of paths where a directory is mounted.

Return Value

array

at line 316
Platform platform()

The platform this container executes and publishes as.

Return Value

Platform

at line 329
string publish(string $address, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)

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

Publish returns a fully qualified ref.

It can also publish platform variants.

Parameters

string $address
array|null $platformVariants
ImageLayerCompression|null $forcedCompression
ImageMediaTypes|null $mediaTypes

Return Value

string

at line 352
Directory rootfs()

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

Return Value

Directory

at line 363
string stderr()

The error stream of the last executed command.

Returns an error if no command was set.

Return Value

string

at line 374
string stdout()

The output stream of the last executed command.

Returns an error if no command was set.

Return Value

string

at line 385
ContainerId sync()

Forces evaluation of the pipeline in the engine.

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

Return Value

ContainerId

at line 394
Container terminal(array|null $cmd = null, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false)

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

Parameters

array|null $cmd
bool|null $experimentalPrivilegedNesting
bool|null $insecureRootCapabilities

Return Value

Container

at line 417
void up(array|null $ports = null, bool|null $random = false, array|null $args = null, bool|null $useEntrypoint = false, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

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.

Parameters

array|null $ports
bool|null $random
array|null $args
bool|null $useEntrypoint
bool|null $experimentalPrivilegedNesting
bool|null $insecureRootCapabilities
bool|null $expand
bool|null $noInit

Return Value

void

at line 458
string user()

Retrieves the user to be set for all commands.

Return Value

string

at line 467
Container withAnnotation(string $name, string $value)

Retrieves this container plus the given OCI anotation.

Parameters

string $name
string $value

Return Value

Container

at line 478
Container withDefaultArgs(array $args)

Configures default arguments for future commands.

Parameters

array $args

Return Value

Container

at line 488
Container withDefaultTerminalCmd(array $args, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false)

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

Parameters

array $args
bool|null $experimentalPrivilegedNesting
bool|null $insecureRootCapabilities

Return Value

Container

at line 507
Container withDirectory(string $path, Directory $directory, array|null $exclude = null, array|null $include = null, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
Directory $directory
array|null $exclude
array|null $include
string|null $owner
bool|null $expand

Return Value

Container

at line 536
Container withEntrypoint(array $args, bool|null $keepDefaultArgs = false)

Retrieves this container but with a different command entrypoint.

Parameters

array $args
bool|null $keepDefaultArgs

Return Value

Container

at line 549
Container withEnvVariable(string $name, string $value, bool|null $expand = false)

Retrieves this container plus the given environment variable.

Parameters

string $name
string $value
bool|null $expand

Return Value

Container

at line 563
Container withExec(array $args, bool|null $useEntrypoint = false, string|null $stdin = '', string|null $redirectStdout = '', string|null $redirectStderr = '', ReturnType|null $expect = null, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false, bool|null $expand = false, bool|null $noInit = false)

Retrieves this container after executing the specified command inside it.

Parameters

array $args
bool|null $useEntrypoint
string|null $stdin
string|null $redirectStdout
string|null $redirectStderr
ReturnType|null $expect
bool|null $experimentalPrivilegedNesting
bool|null $insecureRootCapabilities
bool|null $expand
bool|null $noInit

Return Value

Container

at line 616
Container withExposedPort(int $port, NetworkProtocol|null $protocol = null, string|null $description = null, bool|null $experimentalSkipHealthcheck = false)

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

Parameters

int $port
NetworkProtocol|null $protocol
string|null $description
bool|null $experimentalSkipHealthcheck

Return Value

Container

at line 639
Container withFile(string $path, File $source, int|null $permissions = null, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
File $source
int|null $permissions
string|null $owner
bool|null $expand

Return Value

Container

at line 664
Container withFiles(string $path, array $sources, int|null $permissions = null, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
array $sources
int|null $permissions
string|null $owner
bool|null $expand

Return Value

Container

at line 689
Container withLabel(string $name, string $value)

Retrieves this container plus the given label.

Parameters

string $name
string $value

Return Value

Container

at line 700
Container withMountedCache(string $path, CacheVolume $cache, Directory|null $source = null, CacheSharingMode|null $sharing = null, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
CacheVolume $cache
Directory|null $source
CacheSharingMode|null $sharing
string|null $owner
bool|null $expand

Return Value

Container

at line 729
Container withMountedDirectory(string $path, Directory $source, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
Directory $source
string|null $owner
bool|null $expand

Return Value

Container

at line 750
Container withMountedFile(string $path, File $source, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
File $source
string|null $owner
bool|null $expand

Return Value

Container

at line 771
Container withMountedSecret(string $path, Secret $source, string|null $owner = '', int|null $mode = 256, bool|null $expand = false)

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

Parameters

string $path
Secret $source
string|null $owner
int|null $mode
bool|null $expand

Return Value

Container

at line 796
Container withMountedTemp(string $path, int|null $size = null, bool|null $expand = false)

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.

Parameters

string $path
int|null $size
bool|null $expand

Return Value

Container

at line 812
Container withNewFile(string $path, string $contents, int|null $permissions = 420, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
string $contents
int|null $permissions
string|null $owner
bool|null $expand

Return Value

Container

at line 837
Container withRegistryAuth(string $address, string $username, Secret $secret)

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

Parameters

string $address
string $username
Secret $secret

Return Value

Container

at line 849
Container withRootfs(Directory $directory)

Retrieves the container with the given directory mounted to /.

Parameters

Directory $directory

Return Value

Container

at line 859
Container withSecretVariable(string $name, Secret $secret)

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

Parameters

string $name
Secret $secret

Return Value

Container

at line 876
Container withServiceBinding(string $alias, Service $service)

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.

Parameters

string $alias
Service $service

Return Value

Container

at line 887
Container withUnixSocket(string $path, Socket $source, string|null $owner = '', bool|null $expand = false)

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

Parameters

string $path
Socket $source
string|null $owner
bool|null $expand

Return Value

Container

at line 908
Container withUser(string $name)

Retrieves this container with a different command user.

Parameters

string $name

Return Value

Container

at line 918
Container withWorkdir(string $path, bool|null $expand = false)

Retrieves this container with a different working directory.

Parameters

string $path
bool|null $expand

Return Value

Container

at line 931
Container withoutAnnotation(string $name)

Retrieves this container minus the given OCI annotation.

Parameters

string $name

Return Value

Container

at line 941
Container withoutDefaultArgs()

Retrieves this container with unset default arguments for future commands.

Return Value

Container

at line 950
Container withoutDirectory(string $path, bool|null $expand = false)

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

Parameters

string $path
bool|null $expand

Return Value

Container

at line 963
Container withoutEntrypoint(bool|null $keepDefaultArgs = false)

Retrieves this container with an unset command entrypoint.

Parameters

bool|null $keepDefaultArgs

Return Value

Container

at line 975
Container withoutEnvVariable(string $name)

Retrieves this container minus the given environment variable.

Parameters

string $name

Return Value

Container

at line 985
Container withoutExposedPort(int $port, NetworkProtocol|null $protocol = null)

Unexpose a previously exposed port.

Parameters

int $port
NetworkProtocol|null $protocol

Return Value

Container

at line 998
Container withoutFile(string $path, bool|null $expand = false)

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

Parameters

string $path
bool|null $expand

Return Value

Container

at line 1011
Container withoutFiles(array $paths, bool|null $expand = false)

Retrieves this container with the files at the given paths removed.

Parameters

array $paths
bool|null $expand

Return Value

Container

at line 1024
Container withoutLabel(string $name)

Retrieves this container minus the given environment label.

Parameters

string $name

Return Value

Container

at line 1034
Container withoutMount(string $path, bool|null $expand = false)

Retrieves this container after unmounting everything at the given path.

Parameters

string $path
bool|null $expand

Return Value

Container

at line 1047
Container withoutRegistryAuth(string $address)

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

Parameters

string $address

Return Value

Container

at line 1057
Container withoutSecretVariable(string $name)

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

Parameters

string $name

Return Value

Container

at line 1067
Container withoutUnixSocket(string $path, bool|null $expand = false)

Retrieves this container with a previously added Unix socket removed.

Parameters

string $path
bool|null $expand

Return Value

Container

at line 1082
Container withoutUser()

Retrieves this container with an unset command user.

Should default to root.

Return Value

Container

at line 1093
Container withoutWorkdir()

Retrieves this container with an unset working directory.

Should default to "/".

Return Value

Container

at line 1102
string workdir()

Retrieves the working directory for all commands.

Return Value

string