|
1 | 1 | # PHP Docker API Client |
2 | 2 |
|
3 | | -[](https://github.com/WebProject-xyz/php-docker-api-client/actions/workflows/tests.yml) |
4 | | -[](https://www.codacy.com/gh/WebProject-xyz/php-docker-api-client/dashboard) |
5 | | -[](https://packagist.org/packages/webproject/php-docker-api-client) |
6 | | -[](https://packagist.org/packages/webproject/php-docker-api-client) |
| 3 | +[](https://github.com/WebProject-xyz/php-docker-api-client/actions/workflows/php-tests.yml) |
| 4 | +[](https://github.com/WebProject-xyz/php-docker-api-client/actions/workflows/release.yml) |
| 5 | +[](https://packagist.org/packages/webproject-xyz/docker-api-client) |
| 6 | +[](https://packagist.org/packages/webproject-xyz/docker-api-client) |
| 7 | +[](https://packagist.org/packages/webproject-xyz/docker-api-client) |
| 8 | +[](https://packagist.org/packages/webproject-xyz/docker-api-client) |
7 | 9 |
|
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+). |
9 | | - |
10 | | ---- |
11 | | - |
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 | | -``` |
| 10 | +A modern PHP client for the Docker Engine API (v1.51+), built with [JanePHP](https://github.com/janephp/janephp). |
27 | 11 |
|
28 | 12 | --- |
29 | 13 |
|
30 | 14 | ## 💻 Usage |
31 | 15 |
|
32 | | -### Initialize the Client |
33 | | - |
| 16 | +### Initialize Service |
34 | 17 | ```php |
35 | 18 | use WebProject\DockerApiClient\Client\DockerApiClientWrapper; |
36 | 19 | use WebProject\DockerApiClient\Service\DockerService; |
37 | 20 |
|
38 | | -// Create a client pointing to your local Docker socket |
39 | | -$wrapper = DockerApiClientWrapper::create( |
40 | | - uri: 'http://localhost', |
41 | | - socketPath: '/var/run/docker.sock' |
| 21 | +$service = new DockerService( |
| 22 | + DockerApiClientWrapper::create('http://localhost', '/var/run/docker.sock') |
42 | 23 | ); |
43 | | - |
44 | | -$dockerService = new DockerService($wrapper); |
45 | 24 | ``` |
46 | 25 |
|
47 | | -### List and Inspect Containers |
48 | | - |
| 26 | +### Manage Containers |
49 | 27 | ```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') . " |
| 28 | +// List and inspect containers |
| 29 | +foreach ($service->findAllContainer() as $container) { |
| 30 | + echo "{$container->getName()}: " . ($container->running ? 'Running' : 'Stopped') . " |
61 | 31 | "; |
62 | 32 |
|
63 | | - // Extract virtual hosts from env vars (e.g. for reverse proxies) |
64 | | - $urls = $container->extractUrlsFromEnvVars(['VIRTUAL_HOST', 'DOMAIN_NAME']); |
65 | | - print_r($urls); |
| 33 | + // Extract env-based URLs |
| 34 | + $urls = $container->extractUrlsFromEnvVars(['VIRTUAL_HOST']); |
66 | 35 | } |
67 | 36 | ``` |
68 | 37 |
|
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 | | - |
| 38 | +### CLI Support |
86 | 39 | ```bash |
87 | | -# List all containers |
88 | 40 | bin/docker-api docker:list-containers |
89 | | - |
90 | | -# Listen for Docker socket events |
91 | | -bin/docker-api docker:events:listen |
92 | 41 | ``` |
93 | 42 |
|
94 | 43 | --- |
95 | 44 |
|
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 | 45 | ## 🤝 Contributing |
101 | | - |
102 | | -Contributions are welcome! Please feel free to submit a Pull Request. |
| 46 | +Pull Requests are welcome. |
103 | 47 |
|
104 | 48 | ## 📄 License |
105 | | - |
106 | | -This project is licensed under the MIT License. |
| 49 | +MIT License. |
0 commit comments