Container
class Container extends AbstractObject implements IdAble
An OCI-compatible container, also known as a Docker container.
Properties
$lastQuery | from AbstractObject |
Methods
No description
Turn the container into a Service.
Returns a File representing the container serialized to a tarball.
Initializes this container from a Dockerfile build.
Retrieves default arguments for future commands.
Retrieves a directory at the given path.
Retrieves entrypoint to be prepended to the arguments of all commands.
Retrieves the value of the specified environment variable.
Retrieves the list of environment variables passed to commands.
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.
Retrieves the list of exposed ports.
A unique identifier for this Container.
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.
Retrieves the list of paths where a directory is mounted.
Publishes this container as a new image to the specified address.
The error stream of the last executed command.
The output stream of the last executed command.
Forces evaluation of the pipeline in the engine.
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 anotation.
Configures default arguments for future commands.
Set the default command to invoke for the container's terminal API.
Retrieves this container plus a directory written at the given path.
Retrieves this container but with a different command entrypoint.
Retrieves this container plus the given environment variable.
Retrieves this container after executing the specified command inside it.
Expose a network port.
Retrieves this container plus the contents of the given file copied to the given path.
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 new file written at the given path.
Retrieves this container with a registry authentication for a given address.
Retrieves the container with the given directory mounted to /.
Retrieves this container plus an env variable containing the given secret.
Establish a runtime dependency on a service.
Retrieves this container plus a socket forwarded to the given Unix socket path.
Retrieves this container with a different working directory.
Retrieves this container minus the given OCI annotation.
Retrieves this container with unset default arguments for future commands.
Retrieves this container with the directory at the given path removed.
Retrieves this container with an unset command 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.
Retrieves this container with the files at the given paths 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 with an unset 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 = 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.
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.
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.
at line 102
array
defaultArgs()
Retrieves default arguments for future commands.
at line 113
Directory
directory(string $path, bool|null $expand = false)
Retrieves a directory at the given path.
Mounts are included.
at line 126
array
entrypoint()
Retrieves entrypoint to be prepended to the arguments of all commands.
at line 135
string
envVariable(string $name)
Retrieves the value of the specified environment variable.
at line 145
array
envVariables()
Retrieves the list of environment variables passed to commands.
at line 156
int
exitCode()
The exit code of the last executed command.
Returns an error if no command was set.
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.
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.
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.
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.
at line 234
File
file(string $path, bool|null $expand = false)
Retrieves a file at the given path.
Mounts are included.
at line 247
Container
from(string $address)
Initializes this container from a pulled base image.
at line 257
AbstractId
id()
A unique identifier for this Container.
at line 266
string
imageRef()
The unique image reference which can only be retrieved immediately after the 'Container.From' call.
at line 275
Container
import(File $source, string|null $tag = '')
Reads the container from an OCI tarball.
at line 288
string
label(string $name)
Retrieves the value of the specified label.
at line 298
array
labels()
Retrieves the list of labels passed to container.
at line 307
array
mounts()
Retrieves the list of paths where a directory is mounted.
at line 316
Platform
platform()
The platform this container executes and publishes as.
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.
at line 352
Directory
rootfs()
Retrieves this container's root filesystem. Mounts are not included.
at line 363
string
stderr()
The error stream of the last executed command.
Returns an error if no command was set.
at line 374
string
stdout()
The output stream of the last executed command.
Returns an error if no command was set.
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.
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).
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.
at line 458
string
user()
Retrieves the user to be set for all commands.
at line 467
Container
withAnnotation(string $name, string $value)
Retrieves this container plus the given OCI anotation.
at line 478
Container
withDefaultArgs(array $args)
Configures default arguments for future commands.
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.
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.
at line 536
Container
withEntrypoint(array $args, bool|null $keepDefaultArgs = false)
Retrieves this container but with a different command entrypoint.
at line 549
Container
withEnvVariable(string $name, string $value, bool|null $expand = false)
Retrieves this container plus the given environment variable.
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.
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
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.
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.
at line 689
Container
withLabel(string $name, string $value)
Retrieves this container plus the given label.
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.
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.
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.
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.
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.
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.
at line 837
Container
withRegistryAuth(string $address, string $username, Secret $secret)
Retrieves this container with a registry authentication for a given address.
at line 849
Container
withRootfs(Directory $directory)
Retrieves the container with the given directory mounted to /.
at line 859
Container
withSecretVariable(string $name, Secret $secret)
Retrieves this container plus an env variable containing the given secret.
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.
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.
at line 908
Container
withUser(string $name)
Retrieves this container with a different command user.
at line 918
Container
withWorkdir(string $path, bool|null $expand = false)
Retrieves this container with a different working directory.
at line 931
Container
withoutAnnotation(string $name)
Retrieves this container minus the given OCI annotation.
at line 941
Container
withoutDefaultArgs()
Retrieves this container with unset default arguments for future commands.
at line 950
Container
withoutDirectory(string $path, bool|null $expand = false)
Retrieves this container with the directory at the given path removed.
at line 963
Container
withoutEntrypoint(bool|null $keepDefaultArgs = false)
Retrieves this container with an unset command entrypoint.
at line 975
Container
withoutEnvVariable(string $name)
Retrieves this container minus the given environment variable.
at line 985
Container
withoutExposedPort(int $port, NetworkProtocol|null $protocol = null)
Unexpose a previously exposed port.
at line 998
Container
withoutFile(string $path, bool|null $expand = false)
Retrieves this container with the file at the given path removed.
at line 1011
Container
withoutFiles(array $paths, bool|null $expand = false)
Retrieves this container with the files at the given paths removed.
at line 1024
Container
withoutLabel(string $name)
Retrieves this container minus the given environment label.
at line 1034
Container
withoutMount(string $path, bool|null $expand = false)
Retrieves this container after unmounting everything at the given path.
at line 1047
Container
withoutRegistryAuth(string $address)
Retrieves this container without the registry authentication of a given address.
at line 1057
Container
withoutSecretVariable(string $name)
Retrieves this container minus the given environment variable containing the secret.
at line 1067
Container
withoutUnixSocket(string $path, bool|null $expand = false)
Retrieves this container with a previously added Unix socket removed.
at line 1082
Container
withoutUser()
Retrieves this container with an unset command user.
Should default to root.
at line 1093
Container
withoutWorkdir()
Retrieves this container with an unset working directory.
Should default to "/".
at line 1102
string
workdir()
Retrieves the working directory for all commands.