承接 prsw/docker-php 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

prsw/docker-php

最新稳定版本:v0.3.0

Composer 安装命令:

composer require prsw/docker-php

包简介

Docker PHP SDK

README 文档

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

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-31