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.
- PHP 8.3+
- Docker Engine (Unix socket access)
composer require prsw/docker-phpuse PRSW\Docker\Client;
// Connect to the default Docker Unix socket
$client = Client::withHttpClient();
// List all containers
$containers = $client->containerList();
var_dump($containers);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();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();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);
}use PRSW\Docker\Client;
$client = Client::withHttpClient();
$logs = $client->serviceLogs('service_id', [
'stdout' => true,
'stderr' => true,
]);
foreach ($logs->getBody() as $line) {
var_dump($line);
}$client = Client::withHttpClient(socketPath: '/path/to/docker.sock');$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]);This SDK targets the Docker Engine API v1.47 (Docker 27.x+). The OpenAPI specification is at v1.47.yaml.
MIT