prsw / docker-php
Docker PHP SDK
v0.3.0
2026-05-09 17:19 UTC
Requires
- php: ~8.3.0 || ~8.4.0 || ~8.5.0
- amphp/http-client: ^5.2.1
- amphp/http-client-psr7: ^1.1
- jane-php/open-api-runtime: ^7.11
- laminas/laminas-diactoros: ^3.8
Requires (Dev)
- jane-php/open-api-2: ^7.8
This package is auto-updated.
Last update: 2026-05-09 17:22:27 UTC
README
Asynchronous Docker Engine API client for PHP, built on amphp and generated from the official OpenAPI specification.
This is a rewrite of docker-php/docker-php.
CAUTION Not all endpoints have streaming support implemented.
Requirements
- PHP 8.3+
- Docker Engine (Unix socket access)
Installation
composer require prsw/docker-php
Quick Start
use PRSW\Docker\Client; // Connect to the default Docker Unix socket $client = Client::withHttpClient(); // List all containers $containers = $client->containerList(); var_dump($containers);
Usage
Basic Operations
use PRSW\Docker\Client; $client = Client::withHttpClient(); // Inspect a container $info = $client->containerInspect('container_id'); // Start/stop a container $client->containerStart('container_id'); $client->containerStop('container_id'); // List images $images = $client->imageList();
Streaming Events
Stream real-time Docker events using FETCH_STREAM:
use PRSW\Docker\Client; \Amp\async(function () { $client = Client::withHttpClient(); $response = $client->systemEvents(fetch: Client::FETCH_STREAM); foreach ($response->getBody() as $event) { var_dump($event); } })->await();
Container Logs
use PRSW\Docker\Client; $client = Client::withHttpClient(); $logs = $client->containerLogs('container_id', [ 'stdout' => true, 'stderr' => true, 'since' => (new \DateTime('-7 days'))->getTimestamp(), ]); foreach ($logs->getBody() as $line) { var_dump($line); }
Service Logs
use PRSW\Docker\Client; $client = Client::withHttpClient(); $logs = $client->serviceLogs('service_id', [ 'stdout' => true, 'stderr' => true, ]); foreach ($logs->getBody() as $line) { var_dump($line); }
Custom Socket Path
$client = Client::withHttpClient(socketPath: '/path/to/docker.sock');
Custom Client Options
$client = Client::withHttpClient( socketPath: '/var/run/docker.sock', options: [ 'timeout' => 30, // request timeout in seconds (-1 for no timeout) 'retry' => 3, // number of retries on failure ], );
You can also create a new client instance with different options using:
$client = $client->withHttpClientOptions(['timeout' => 60, 'retry' => 5]);
API Version
This SDK targets the Docker Engine API v1.47 (Docker 27.x+). The OpenAPI specification is at v1.47.yaml.
License
MIT