PHPackages                             sangezar/docker-php-client - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [HTTP &amp; Networking](/categories/http)
4. /
5. sangezar/docker-php-client

ActiveLibrary[HTTP &amp; Networking](/categories/http)

sangezar/docker-php-client
==========================

A PHP client for the Docker Engine API

v1.0.0(1y ago)112MITPHPPHP ^8.1CI passing

Since Apr 13Pushed 1y ago1 watchersCompare

[ Source](https://github.com/sangezar/docker-php-client)[ Packagist](https://packagist.org/packages/sangezar/docker-php-client)[ RSS](/packages/sangezar-docker-php-client/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (6)Versions (2)Used By (0)

🐳 Docker PHP Client
===================

[](#-docker-php-client)

[![Latest Version on Packagist](https://camo.githubusercontent.com/0785e9bb27df172dfe13df4181d20971ddab3f388516f5bc6ed05a146ee3c40d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616e67657a61722f646f636b65722d7068702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sangezar/docker-php-client)[![Total Downloads](https://camo.githubusercontent.com/832c58dbe63cdb0655033610ff77a07bbe381202c91bdd9f2f225aa20e391ac4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616e67657a61722f646f636b65722d7068702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sangezar/docker-php-client)[![License](https://camo.githubusercontent.com/455d76ce751fee2d2dbd2b59d102a1c9d814ec92fdc85655f9ba61ca2ed58b7a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f73616e67657a61722f646f636b65722d7068702d636c69656e742e7376673f7374796c653d666c61742d737175617265)](LICENSE)

A modern, powerful, and elegant Docker API client for PHP applications with cluster support.

✨ Features
----------

[](#-features)

- 🚀 Full Docker API support
- 🔄 Container management (create, inspect, start, stop, remove)
- 🖼️ Image operations (build, pull, push, tag)
- 🌐 Network configuration &amp; management
- 💾 Volume creation &amp; management
- 🔍 System information &amp; events
- 🔐 TLS authentication support
- 🔌 Unix socket &amp; TCP connection support
- 📦 PSR-18 compatible HTTP client
- 🧩 Fluent interfaces for all configurations
- 🔧 Comprehensive exception handling
- 🏘️ Docker Swarm &amp; cluster operations
- ⚡ Asynchronous operations support

📋 Requirements
--------------

[](#-requirements)

- PHP 8.2 or higher
- ext-json
- PSR-18 HTTP Client
- Docker Engine API v1.41+

🛠️ Installation
---------------

[](#️-installation)

Install the package via Composer:

```
composer require sangezar/docker-php-client
```

🚀 Quick Start
-------------

[](#-quick-start)

### Connect to Docker via Unix Socket (Default)

[](#connect-to-docker-via-unix-socket-default)

```
use Sangezar\DockerClient\DockerClient;

// Connect to local Docker daemon through unix socket
$client = DockerClient::createUnix();

// List all containers
$containers = $client->container()->list(['all' => true]);
```

### Connect to Docker via TCP

[](#connect-to-docker-via-tcp)

```
use Sangezar\DockerClient\DockerClient;

// Connect to remote Docker daemon through TCP
$client = DockerClient::createTcp('tcp://docker-host:2375');

// Get system information
$info = $client->system()->info();
```

### Connect to Docker via TCP with TLS

[](#connect-to-docker-via-tcp-with-tls)

```
use Sangezar\DockerClient\DockerClient;

// Connect to remote Docker daemon with TLS
$client = DockerClient::createTcp(
    'tcp://docker-host:2376',
    '/path/to/cert.pem',
    '/path/to/key.pem',
    '/path/to/ca.pem'
);
```

📊 Working with Containers
-------------------------

[](#-working-with-containers)

### Create and Run a Container

[](#create-and-run-a-container)

```
use Sangezar\DockerClient\Config\ContainerConfig;

// Create container configuration
$config = ContainerConfig::create()
    ->setImage('nginx:latest')
    ->setName('my-nginx')
    ->exposePorts(80, 443)
    ->addEnv('NGINX_HOST', 'example.com')
    ->addVolume('/var/www', '/usr/share/nginx/html')
    ->setRestartPolicy('always');

// Create container
$container = $client->container()->create($config);

// Start container
$client->container()->start($container['Id']);
```

### List Containers

[](#list-containers)

```
// List all running containers
$runningContainers = $client->container()->list();

// List all containers (including stopped ones)
$allContainers = $client->container()->list(['all' => true]);

// Filter containers
$filtered = $client->container()->list([
    'filters' => [
        'status' => ['running'],
        'label' => ['com.example.group=web']
    ]
]);
```

### Container Lifecycle Management

[](#container-lifecycle-management)

```
$containerId = 'my-container';

// Inspect container
$info = $client->container()->inspect($containerId);

// Stop container
$client->container()->stop($containerId, 10); // 10 seconds timeout

// Restart container
$client->container()->restart($containerId);

// Remove container
$client->container()->remove($containerId, true, true); // force, remove volumes
```

🖼️ Working with Images
----------------------

[](#️-working-with-images)

```
// Pull an image
$client->image()->create('nginx', 'latest');

// List images
$images = $client->image()->list(['all' => true]);

// Build an image
$buildOptions = new ImageBuildOptions();
$buildOptions->setTag('my-app:latest')
    ->setContext('/path/to/context')
    ->setDockerfile('Dockerfile.prod');

$client->image()->buildWithOptions($buildOptions);

// Tag an image
$client->image()->tag('my-app:latest', 'registry.example.com/my-app', 'v1.0');

// Push an image
$client->image()->push('registry.example.com/my-app:v1.0');
```

🌐 Working with Networks
-----------------------

[](#-working-with-networks)

```
use Sangezar\DockerClient\Config\NetworkConfig;

// Create a network
$networkConfig = NetworkConfig::create()
    ->setName('app-network')
    ->setDriver('bridge')
    ->addSubnet('172.28.0.0/16', '172.28.0.1')
    ->addLabel('environment', 'production');

$network = $client->network()->create($networkConfig);

// Connect a container to network
$client->network()->connect('app-network', 'my-container', [
    'Aliases' => ['web-server']
]);

// List networks
$networks = $client->network()->list();
```

💾 Working with Volumes
----------------------

[](#-working-with-volumes)

```
use Sangezar\DockerClient\Config\VolumeConfig;

// Create a volume
$volumeConfig = VolumeConfig::create()
    ->setName('data-volume')
    ->setDriver('local')
    ->addLabel('backup', 'daily');

$volume = $client->volume()->create($volumeConfig);

// Inspect volume
$volumeInfo = $client->volume()->inspect('data-volume');

// List volumes
$volumes = $client->volume()->list();
```

🏘️ Working with Docker Clusters
-------------------------------

[](#️-working-with-docker-clusters)

```
use Sangezar\DockerClient\Cluster\DockerCluster;

// Create a cluster
$cluster = new DockerCluster();

// Add nodes to cluster
$cluster->addNode('node1', DockerClient::createTcp('tcp://node1:2375'));
$cluster->addNode('node2', DockerClient::createTcp('tcp://node2:2375'));

// Get all containers across the cluster
$allContainers = $cluster->nodes()->containers()->list(['all' => true]);

// Filter nodes by name pattern
$webNodes = $cluster->getNodeCollection()->filter(function($client, $name) {
    return str_contains($name, 'web');
});

// Create containers on specific nodes
$webNodes->containers()->create($containerConfig);
```

🧩 Advanced Usage
----------------

[](#-advanced-usage)

### Custom HTTP Client

[](#custom-http-client)

```
use Sangezar\DockerClient\Config\ClientConfig;
use Sangezar\DockerClient\DockerClient;
use GuzzleHttp\Client;

// Create custom HTTP client
$httpClient = new Client([
    'timeout' => 30,
    'connect_timeout' => 5
]);

// Create client config
$config = new ClientConfig();
$config->setEndpoint('unix:///var/run/docker.sock');

// Create Docker client with custom HTTP client
$client = new DockerClient($config, $httpClient);
```

### Handle Events Stream

[](#handle-events-stream)

```
// Get Docker events stream
$events = $client->system()->events([
    'filters' => [
        'type' => ['container'],
        'event' => ['start', 'stop', 'die']
    ]
]);

// Process events
foreach ($events as $event) {
    $type = $event['Type'];
    $action = $event['Action'];
    $id = $event['Actor']['ID'];

    echo "Event: {$type} {$action} on {$id}\n";
}
```

📚 Documentation
---------------

[](#-documentation)

For full documentation, please visit [the documentation site](https://sangezar.github.io/docker-php-client/).

Documentation is available in:

- [English](https://sangezar.github.io/docker-php-client/en/)
- [Ukrainian](https://sangezar.github.io/docker-php-client/ua/)

🧪 Testing
---------

[](#-testing)

```
composer test
```

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request

📄 License
---------

[](#-license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

⭐ Star the Project
------------------

[](#-star-the-project)

If you find this client useful, please consider giving it a star on GitHub! It helps to increase the visibility of the project and motivate further development.

🙏 Credits
---------

[](#-credits)

- [Docker API Documentation](https://docs.docker.com/engine/api/)

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance46

Moderate activity, may be stable

Popularity7

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

400d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bb89dcb20d9283445d8658502698bea1e3bc3e87b740371926a1114d9beb29fa?d=identicon)[sangezar](/maintainers/sangezar)

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sangezar-docker-php-client/health.svg)

```
[![Health](https://phpackages.com/badges/sangezar-docker-php-client/health.svg)](https://phpackages.com/packages/sangezar-docker-php-client)
```

###  Alternatives

[shopify/shopify-api

Shopify API Library for PHP

4634.8M16](/packages/shopify-shopify-api)[laudis/neo4j-php-client

Neo4j-PHP-Client is the most advanced PHP Client for Neo4j

184616.9k31](/packages/laudis-neo4j-php-client)[akamai-open/edgegrid-client

Implements the Akamai {OPEN} EdgeGrid Authentication specified by https://developer.akamai.com/introduction/Client\_Auth.html

482.5M6](/packages/akamai-open-edgegrid-client)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[claude-php/claude-php-sdk

A universal, framework-agnostic PHP SDK for the Anthropic Claude API with PSR compliance

13920.7k2](/packages/claude-php-claude-php-sdk)[art4/requests-psr18-adapter

Use WordPress/Requests as a PSR-18 HTTP client

153.3k](/packages/art4-requests-psr18-adapter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
