Skip to content

Commit 48659c2

Browse files
committed
fix(docs): update readme and add code examples
Signed-off-by: Benjamin Fahl <git@fahl-design.de>
1 parent 4d97c1e commit 48659c2

1 file changed

Lines changed: 97 additions & 10 deletions

File tree

README.md

Lines changed: 97 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,106 @@
1-
# php-docker-api-client - A PHP docker API client
1+
# PHP Docker API Client
22

3+
[![QA](https://github.com/WebProject-xyz/php-docker-api-client/actions/workflows/tests.yml/badge.svg)](https://github.com/WebProject-xyz/php-docker-api-client/actions/workflows/tests.yml)
4+
[![Codacy Badge](https://app.codacy.com/project/badge/Grade/86f56d0d268d41e78c56658970e5b721)](https://www.codacy.com/gh/WebProject-xyz/php-docker-api-client/dashboard)
5+
[![Latest Stable Version](https://poser.pugx.org/webproject/php-docker-api-client/v/stable)](https://packagist.org/packages/webproject/php-docker-api-client)
6+
[![License](https://poser.pugx.org/webproject/php-docker-api-client/license)](https://packagist.org/packages/webproject/php-docker-api-client)
37

4-
## Based on Docker API Version spec [docker-v1.51.yaml](spec/docker-v1.51.yaml)
5-
> converted to openapi v3.1.0 [docker-v1.51-patched.yaml](spec/docker-v1.51-patched.yaml) see [UPDATE.md](spec/UPDATE.md) how to upgrade client
8+
A modern, high-level PHP client for the Docker Engine API, built on top of [JanePHP](https://github.com/janephp/janephp) and supporting the latest Docker API specs (v1.51+).
69

7-
## Example
10+
---
811

9-
> list running all containers
10-
```shell
11-
bin/docker-api docker:list-containers
12+
## 🚀 Features
13+
14+
- **High-level Service Layer**: Easy access to container information through the `DockerService`.
15+
- **Modern PHP**: Fully typed, leveraging PHP 8.3+ features.
16+
- **Auto-generated Models**: Powered by JanePHP based on official Docker OpenAPI specs.
17+
- **DTO Support**: Includes `DockerContainerDto` for easy data handling and URL extraction from environment variables.
18+
- **CLI Tool**: Built-in `bin/docker-api` for quick interactions.
19+
20+
---
21+
22+
## 📦 Installation
23+
24+
```bash
25+
composer require webproject/php-docker-api-client
26+
```
27+
28+
---
29+
30+
## 💻 Usage
31+
32+
### Initialize the Client
33+
34+
```php
35+
use WebProject\DockerApiClient\Client\DockerApiClientWrapper;
36+
use WebProject\DockerApiClient\Service\DockerService;
37+
38+
// Create a client pointing to your local Docker socket
39+
$wrapper = DockerApiClientWrapper::create(
40+
uri: 'http://localhost',
41+
socketPath: '/var/run/docker.sock'
42+
);
43+
44+
$dockerService = new DockerService($wrapper);
45+
```
46+
47+
### List and Inspect Containers
48+
49+
```php
50+
// Get all containers (includes inspection data)
51+
$containers = $dockerService->findAllContainer();
52+
53+
foreach ($containers as $id => $container) {
54+
echo "Container ID: {$container->id}
55+
";
56+
echo "Name: {$container->getName()}
57+
";
58+
echo "Image: {$container->image}
59+
";
60+
echo "Running: " . ($container->running ? 'Yes' : 'No') . "
61+
";
62+
63+
// Extract virtual hosts from env vars (e.g. for reverse proxies)
64+
$urls = $container->extractUrlsFromEnvVars(['VIRTUAL_HOST', 'DOMAIN_NAME']);
65+
print_r($urls);
66+
}
1267
```
1368

14-
> listen for socket events
15-
```shell
69+
### Direct API Access
70+
71+
For low-level access to all Docker API endpoints, use the generated JanePHP client:
72+
73+
```php
74+
$client = $wrapper->getDockerClient();
75+
$info = $client->systemInfo();
76+
echo "Docker Server Version: " . $info->getServerVersion() . "
77+
";
78+
```
79+
80+
---
81+
82+
## 🛠 CLI Usage
83+
84+
The package includes a command-line interface for common tasks:
85+
86+
```bash
87+
# List all containers
88+
bin/docker-api docker:list-containers
89+
90+
# Listen for Docker socket events
1691
bin/docker-api docker:events:listen
1792
```
1893

19-
#### Generated with [janephp/janephp](https://github.com/janephp/janephp)
94+
---
95+
96+
## 📖 Development
97+
98+
The underlying client is generated from the Docker API spec. See [UPDATE.md](spec/UPDATE.md) for details on how to update the generated classes when new Docker API versions are released.
99+
100+
## 🤝 Contributing
101+
102+
Contributions are welcome! Please feel free to submit a Pull Request.
103+
104+
## 📄 License
105+
106+
This project is licensed under the MIT License.

0 commit comments

Comments
 (0)