Skip to main content
An image archive, a build context and a container filesystem export are not interchangeable. Choose the matching API operation:

Save an image

Use executeRawEndpoint(new Docker\API\Endpoint\ImageGet($imageName)) and require HTTP 200, then save the body in chunks using the archive download pattern. The default generated imageGet() result is null; it does not give you a tar stream. For more than one image, use new ImageGetAll(['names' => ['image-a:tag', 'image-b:tag']]) with the raw endpoint. Specify the names explicitly rather than accidentally exporting every image on the daemon.

Load an image archive

Loading creates or updates image records and tags on the daemon. Use a tar produced by an image-save operation and a development daemon. This call has no BuildStream/CreateImageStream wrapper; its progress response must be handled separately.
The archive is sent as a resource, so PHP does not load the tar file into a string first. This example buffers only the quiet progress response. For a verbose or long-lived JSON stream, use a bounded incremental JSON-line reader instead. Reading the progress is necessary: HTTP 200 alone does not prove that the daemon accepted all of the image data.

Root-filesystem import is different

imageCreate() with fromSrc imports a root filesystem, not an image-save archive. Use fromSrc => '-' for a request-body import, or a source URL for the daemon to download. Remote source URLs are fetched by the daemon, not PHP; do not accept arbitrary URLs from untrusted callers. In this API line, imageCreate()’s request body is ?string, unlike the resource/PSR-7-stream bodies supported by imageBuild(), imageLoad() and putContainerArchive(). Do not pass a file resource to imageCreate() and expect it to behave like an image load. Choose the operation and payload type deliberately, especially for large archives.