Container
class Container extends AbstractObject implements IdAble, Exportable, Node, Syncer
An OCI-compatible container, also known as a Docker container.
Properties
| $lastQuery | from AbstractObject |
Methods
No description
Turn the container into a Service.
Package the container state as an OCI image, and return it as a tar archive
The combined buffered standard output and standard error stream of the last executed command
Return the container's default arguments.
Retrieve a directory from the container's root filesystem
Retrieves this container's configured docker healthcheck.
Return the container's OCI entrypoint.
Retrieves the value of the specified persistent environment variable.
Retrieves the list of persistent environment variables configured on the container.
check if a file or directory exists
The exit code of the last executed command
EXPERIMENTAL API! Subject to change/removal at any time.
EXPERIMENTAL API! Subject to change/removal at any time.
Writes the container as an OCI tarball to the destination file path on the host.
Exports the container as an image to the host's container image store.
Retrieves the list of exposed ports.
Download a container image, and apply it to the container state. All previous state will be lost.
The unique image reference which can only be retrieved immediately after the 'Container.From' call.
Retrieves the value of the specified label.
Retrieves the list of labels passed to container.
Returns the image layer or configuration blob with the given digest as a File.
Computes and returns the manifest for this container as a File.
Retrieves the list of paths where a directory is mounted.
Package the container state as an OCI image, and publish it to a registry
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.
Return file status
The buffered standard error stream of the last executed command
The buffered standard output stream of the last executed command
Opens an interactive terminal for this container using its configured default terminal command if not overridden by args (or sh as a fallback default).
Starts a Service and creates a tunnel that forwards traffic from the caller's network to that service.
Retrieves the user to be set for all commands.
Retrieves this container plus the given OCI annotation.
Configures default arguments for future commands. Like CMD in Dockerfile.
Set the default command to invoke for the container's terminal API.
Return a new container snapshot, with a directory added to its filesystem
Retrieves this container with the specificed docker healtcheck command set.
Set an OCI-style entrypoint. It will be included in the container's OCI configuration. Note, withExec ignores the entrypoint by default.
Export environment variables from an env-file to the container.
Set a new environment variable in the container.
Execute a command in the container, and return a new snapshot of the container state after execution.
Expose a network port. Like EXPOSE in Dockerfile (but with healthcheck support)
Retrieves this container plus the contents of the given files copied to the given path.
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. Any writes will be ephemeral to a single withExec call; they will not be persisted to subsequent withExecs.
Retrieves this container plus a volume mounted at the given path.
Return a new container snapshot, with a file added to its filesystem with text content
Attach credentials for future publishing to a registry. Use in combination with publish
Change the container's root filesystem. The previous root filesystem will be lost.
Set a new environment variable, using a secret value
Establish a runtime dependency from a container to a network service.
Return a snapshot with a symlink
Retrieves this container plus a socket forwarded to the given Unix socket path.
Set a new non-secret environment variable for future execs without invalidating exec cache when only its value changes.
Change the container's working directory. Like WORKDIR in Dockerfile.
Retrieves this container minus the given OCI annotation.
Remove the container's default arguments.
Return a new container snapshot, with a directory removed from its filesystem
Retrieves this container without a configured docker healtcheck command.
Reset the container's OCI entrypoint.
Retrieves this container minus the given environment variable.
Unexpose a previously exposed port.
Retrieves this container with the file at the given path removed.
Return a new container spanshot with specified files removed
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 minus the given environment variable containing the secret.
Retrieves this container with a previously added Unix socket removed.
Retrieves this container with an unset command user.
Retrieves this container minus the given volatile environment variable.
Unset the container's working directory.
Retrieves the working directory for all commands.
Details
in
AbstractObject at line 13
__construct(AbstractClient $client, QueryBuilderChain $queryBuilderChain)
No description
in
AbstractObject at line 19
protected null|array|string|int|float|bool
queryLeaf(QueryBuilder $leafQueryBuilder, string $leafKey)
No description
at line 21
Service
asService(array|null $args = [], 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.
at line 54
File
asTarball(array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)
Package the container state as an OCI image, and return it as a tar archive
at line 77
string
combinedOutput()
The combined buffered standard output and standard error stream of the last executed command
Returns an error if no command was executed
at line 86
array
defaultArgs()
Return the container's default arguments.
at line 97
Directory
directory(string $path, bool|null $expand = false)
Retrieve a directory from the container's root filesystem
Mounts are included.
at line 110
HealthcheckConfig|null
dockerHealthcheck()
Retrieves this container's configured docker healthcheck.
at line 124
array
entrypoint()
Return the container's OCI entrypoint.
at line 133
string
envVariable(string $name)
Retrieves the value of the specified persistent environment variable.
at line 143
array
envVariables()
Retrieves the list of persistent environment variables configured on the container.
at line 152
bool
exists(string $path, ExistsType|null $expectedType = null, bool|null $doNotFollowSymlinks = false, bool|null $expand = false)
check if a file or directory exists
at line 177
int
exitCode()
The exit code of the last executed command
Returns an error if no command was executed
at line 190
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.
at line 203
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.
at line 215
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.
at line 242
void
exportImage(string $name, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)
Exports the container as an image to the host's container image store.
at line 267
array
exposedPorts()
Retrieves the list of exposed ports.
This includes ports already exposed by the image, even if not explicitly added with dagger.
at line 278
File
file(string $path, bool|null $expand = false)
Retrieves a file at the given path.
Mounts are included.
at line 291
Container
from(string $address, Service|null $registryService = null, RegistryProtocol|null $protocol = null, bool|null $insecureSkipTLSVerify = false)
Download a container image, and apply it to the container state. All previous state will be lost.
at line 314
Id
id()
A unique identifier for this Container.
at line 323
string
imageRef()
The unique image reference which can only be retrieved immediately after the 'Container.From' call.
at line 332
Container
import(File $source, string|null $tag = '')
Reads the container from an OCI tarball.
at line 345
string
label(string $name)
Retrieves the value of the specified label.
at line 355
array
labels()
Retrieves the list of labels passed to container.
at line 364
File
layer(string $id, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)
Returns the image layer or configuration blob with the given digest as a File.
at line 383
File
manifest(ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null)
Computes and returns the manifest for this container as a File.
at line 400
array
mounts()
Retrieves the list of paths where a directory is mounted.
at line 409
Platform
platform()
The platform this container executes and publishes as.
at line 420
string
publish(string $address, array|null $platformVariants = null, ImageLayerCompression|null $forcedCompression = null, ImageMediaTypes|null $mediaTypes = null, Service|null $registryService = null, RegistryProtocol|null $protocol = null, bool|null $insecureSkipTLSVerify = false)
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
at line 455
Directory
rootfs()
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.
at line 464
Stat|null
stat(string $path, bool|null $doNotFollowSymlinks = false)
Return file status
at line 484
string
stderr()
The buffered standard error stream of the last executed command
Returns an error if no command was executed
at line 495
string
stdout()
The buffered standard output stream of the last executed command
Returns an error if no command was executed
at line 506
Syncer
sync()
Forces evaluation of the pipeline in the engine.
It doesn't run the default command if no exec has been set.
at line 516
Container
terminal(array|null $cmd = [], 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).
at line 539
void
up(bool|null $random = false, array|null $ports = null, array|null $args = [], 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.
at line 580
string
user()
Retrieves the user to be set for all commands.
at line 589
Container
withAnnotation(string $name, string $value)
Retrieves this container plus the given OCI annotation.
at line 600
Container
withDefaultArgs(array $args)
Configures default arguments for future commands. Like CMD in Dockerfile.
at line 610
Container
withDefaultTerminalCmd(array $args, bool|null $experimentalPrivilegedNesting = false, bool|null $insecureRootCapabilities = false)
Set the default command to invoke for the container's terminal API.
at line 629
Container
withDirectory(string $path, Directory $source, array|null $exclude = [], array|null $include = [], bool|null $gitignore = false, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false, int|null $permissions = null)
Return a new container snapshot, with a directory added to its filesystem
at line 670
Container
withDockerHealthcheck(array $args, bool|null $shell = null, string|null $interval = null, string|null $timeout = null, string|null $startPeriod = null, string|null $startInterval = null, int|null $retries = null)
Retrieves this container with the specificed docker healtcheck command set.
at line 705
Container
withEntrypoint(array $args, bool|null $keepDefaultArgs = false)
Set an OCI-style entrypoint. It will be included in the container's OCI configuration. Note, withExec ignores the entrypoint by default.
at line 718
Container
withEnvFileVariables(EnvFile $source)
Export environment variables from an env-file to the container.
at line 728
Container
withEnvVariable(string $name, string $value, bool|null $expand = false)
Set a new environment variable in the container.
at line 742
Container
withError(string $err)
Raise an error.
at line 752
Container
withExec(array $args, bool|null $useEntrypoint = false, string|null $stdin = '', string|null $redirectStdin = '', 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)
Execute a command in the container, and return a new snapshot of the container state after execution.
at line 809
Container
withExposedPort(int $port, NetworkProtocol|null $protocol = null, string|null $description = null, bool|null $experimentalSkipHealthcheck = false)
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
at line 832
Container
withFile(string $path, File $source, int|null $permissions = null, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Return a container snapshot with a file added
at line 861
Container
withFiles(string $path, array $sources, int|null $permissions = null, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Retrieves this container plus the contents of the given files copied to the given path.
at line 890
Container
withLabel(string $name, string $value)
Retrieves this container plus the given label.
at line 901
Container
withMountedCache(string $path, CacheVolume $cache, Directory|null $source = null, CacheSharingMode|null $sharing = null, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Retrieves this container plus a cache volume mounted at the given path.
at line 934
Container
withMountedDirectory(string $path, Directory $source, string|null $owner = '', bool|null $inheritOwner = false, bool|null $readOnly = false, bool|null $expand = false)
Retrieves this container plus a directory mounted at the given path.
at line 963
Container
withMountedFile(string $path, File $source, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Retrieves this container plus a file mounted at the given path.
at line 988
Container
withMountedSecret(string $path, Secret $source, string|null $owner = '', bool|null $inheritOwner = false, int|null $mode = 256, bool|null $expand = false)
Retrieves this container plus a secret mounted into a file at the given path.
at line 1017
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.
at line 1033
Container
withMountedVolume(string $path, Volume $volume, bool|null $readOnly = false, bool|null $expand = false)
Retrieves this container plus a volume mounted at the given path.
at line 1054
Container
withNewFile(string $path, string $contents, int|null $permissions = 420, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Return a new container snapshot, with a file added to its filesystem with text content
at line 1083
Container
withRegistryAuth(string $address, string $username, Secret $secret)
Attach credentials for future publishing to a registry. Use in combination with publish
at line 1095
Container
withRootfs(Directory $directory)
Change the container's root filesystem. The previous root filesystem will be lost.
at line 1105
Container
withSecretVariable(string $name, Secret $secret)
Set a new environment variable, using a secret value
at line 1122
Container
withServiceBinding(string $alias, Service $service)
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.
at line 1133
Container
withSymlink(string $target, string $linkName, bool|null $expand = false)
Return a snapshot with a symlink
at line 1147
Container
withUnixSocket(string $path, Socket $source, string|null $owner = '', bool|null $inheritOwner = false, bool|null $expand = false)
Retrieves this container plus a socket forwarded to the given Unix socket path.
at line 1172
Container
withUser(string $name)
Retrieves this container with a different command user.
at line 1184
Container
withVolatileVariable(string $name, string $value)
Set a new non-secret environment variable for future execs without invalidating exec cache when only its value changes.
This is an expert-only escape hatch. If a volatile value affects observable exec results, stale cached results may be reused.
at line 1195
Container
withWorkdir(string $path, bool|null $expand = false)
Change the container's working directory. Like WORKDIR in Dockerfile.
at line 1208
Container
withoutAnnotation(string $name)
Retrieves this container minus the given OCI annotation.
at line 1218
Container
withoutDefaultArgs()
Remove the container's default arguments.
at line 1227
Container
withoutDirectory(string $path, bool|null $expand = false)
Return a new container snapshot, with a directory removed from its filesystem
at line 1240
Container
withoutDockerHealthcheck()
Retrieves this container without a configured docker healtcheck command.
at line 1249
Container
withoutEntrypoint(bool|null $keepDefaultArgs = false)
Reset the container's OCI entrypoint.
at line 1261
Container
withoutEnvVariable(string $name)
Retrieves this container minus the given environment variable.
at line 1271
Container
withoutExposedPort(int $port, NetworkProtocol|null $protocol = null)
Unexpose a previously exposed port.
at line 1284
Container
withoutFile(string $path, bool|null $expand = false)
Retrieves this container with the file at the given path removed.
at line 1297
Container
withoutFiles(array $paths, bool|null $expand = false)
Return a new container spanshot with specified files removed
at line 1310
Container
withoutLabel(string $name)
Retrieves this container minus the given environment label.
at line 1320
Container
withoutMount(string $path, bool|null $expand = false)
Retrieves this container after unmounting everything at the given path.
at line 1333
Container
withoutRegistryAuth(string $address)
Retrieves this container without the registry authentication of a given address.
at line 1343
Container
withoutSecretVariable(string $name)
Retrieves this container minus the given environment variable containing the secret.
at line 1353
Container
withoutUnixSocket(string $path, bool|null $expand = false)
Retrieves this container with a previously added Unix socket removed.
at line 1368
Container
withoutUser()
Retrieves this container with an unset command user.
Should default to root.
at line 1377
Container
withoutVolatileVariable(string $name)
Retrieves this container minus the given volatile environment variable.
at line 1389
Container
withoutWorkdir()
Unset the container's working directory.
Should default to "/".
at line 1398
string
workdir()
Retrieves the working directory for all commands.