Docker\Context\Context can stream a directory through the system
tar command without first loading the whole archive into a PHP string.
Create a build/Dockerfile next to your PHP script:
imageBuild() returns a BuildStream in the default fetch mode, not an array
of completed build results. The callback receives generated BuildInfo models.
Check the frames for daemon-reported build errors as well as handling endpoint
exceptions.
Context requires GNU or BSD tar on the machine running PHP. It leaves out
the paths a .dockerignore file in the context directory excludes, as
docker build does. Patterns follow the Docker CLI: *, ?, character
classes, ** for any number of directories, ! to re-include a path, and the
last matching pattern wins. The Dockerfile and .dockerignore are always
sent, because the daemon reads them; it then drops them if your patterns
exclude them. If you build with a differently named Dockerfile through the
dockerfile option, add a ! exception for it.
To archive the whole directory, as 3.x did by default:
Build arguments and other query options
JSON-valued build options are strings. Continue with the$docker client from
above, but create a fresh context for each request:
pull is string-valued in this specification, while nocache is boolean.
Do not pre-URL-encode the JSON options. Declare ARG APP_MODE in the Dockerfile
if the build uses it. Build arguments are not a safe channel for secrets.
To apply several tags, pass a list to t, for example
't' => ['docker-php-example:latest', 'docker-php-example:1.0']. Docker PHP
sends one t parameter per tag. Lists require client 3.3.0 or later.
A streamed context is consumed by the first request. The original tar process
is not rewindable. Keep the context alive until the request has
finished, and do not assume a process-backed stream has a known byte length.
Construct a small context in PHP
ContextBuilder creates a temporary context directory and a Dockerfile. It is
useful when the build has a few generated files, without maintaining a separate
directory in your application:
Context is destroyed. It is
not a complete Dockerfile parser or a Buildx replacement. Prefer an ordinary
Dockerfile when the build needs features the helper does not express.
Private base images
Pass a registry credential map inX-Registry-Config, not the single
X-Registry-Auth object used for pull/push. For example, construct the header
from credentials already held in $username and $token:
https://index.docker.io/v1/, rather than
just its hostname. Do not include registry-config headers in request logs.
Builder backend limits
Docker’s specification defaults theversion query parameter to the classic builder
('1'). Whether that builder is available depends on your daemon. Merely
setting version => '2' does not implement BuildKit session handling, secret
mounts, SSH forwarding or Buildx workflows in this client. Validate the backend
and required features against your development daemon; these examples are not
a promise of full BuildKit support.