Skip to content

Commit cbff5d5

Browse files
committed
Update README.md
1 parent 8f1ebb3 commit cbff5d5

1 file changed

Lines changed: 85 additions & 1 deletion

File tree

README.md

Lines changed: 85 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# clue/docker-react [![Build Status](https://travis-ci.org/clue/php-docker-react.svg?branch=master)](https://travis-ci.org/clue/php-docker-react)
22

3-
Simple async/streaming access to the Docker API, built on top of React PHP
3+
Simple async/streaming access to the [Docker](https://www.docker.com/) API, built on top of [React PHP](http://reactphp.org/).
4+
5+
[Docker](https://www.docker.com/) is a popular open source platform
6+
to run and share applications within isolated, lightweight containers.
7+
The [Docker Remote API](https://wiki.asterisk.org/wiki/display/AST/The+Asterisk+Manager+TCP+IP+API)
8+
allows you to control and monitor your containers and images.
9+
Among others, it can be used to list existing images, download new images,
10+
execute arbitrary commands within isolated containers, stop running containers and much more.
11+
12+
* **Async execution of Actions** -
13+
Send any number of actions (commands) to your Docker daemon in parallel and
14+
process their responses as soon as results come in.
15+
The Promise-based design provides a *sane* interface to working with out of bound responses.
16+
* **Lightweight, SOLID design** -
17+
Provides a thin abstraction that is [*just good enough*](http://en.wikipedia.org/wiki/Principle_of_good_enough)
18+
and does not get in your way.
19+
This library is merely a very thin wrapper around the Remote API.
20+
* **Good test coverage** -
21+
Comes with an automated tests suite and is regularly tested in the *real world*
422

523
> Note: This project is in early alpha stage! Feel free to report any issues you encounter.
624
@@ -23,6 +41,72 @@ $loop->run();
2341

2442
See also the [examples](examples).
2543

44+
## Usage
45+
46+
### Factory
47+
48+
The `Factory` is responsible for creating your `Client` instance.
49+
It also registers everything with the main `EventLoop`.
50+
51+
```php
52+
$loop = \React\EventLoop\Factory::create();
53+
$factory = new Factory($loop);
54+
```
55+
56+
The `createClient($url = null)` method can be used to create a new `Client`.
57+
It helps with constructing a `Browser` object for the given remote URL.
58+
59+
```php
60+
// create client with default URL (unix:///var/run/docker.sock)
61+
$client = $factory->createClient();
62+
63+
// explicitly use given UNIX socket path
64+
$client = $factory->createClient('unix:///var/run/docker.sock');
65+
66+
// connect via TCP/IP
67+
$client = $factory->createClient('http://10.0.0.2:8000/');
68+
```
69+
70+
### Client
71+
72+
The `Client` is responsible for assembling and sending HTTP requests to the Docker API.
73+
It requires a `Browser` object bound to the main `EventLoop` in order to handle async requests and a base URL.
74+
The recommended way to create a `Client` is using the `Factory` (see above).
75+
76+
All public methods on the `Client` resemble the API described in the [Remote API documentation](https://docs.docker.com/reference/api/docker_remote_api_v1.15/) like this:
77+
78+
```php
79+
$client->containerList($all, $size);
80+
$client->containerCreate($config, $name);
81+
$client->containerStart($name);
82+
$client->containerKill($name, $signal);
83+
$client->containerRemove($name, $v, $force);
84+
85+
$client->imageList($all);
86+
$client->imageSearch($term);
87+
$client->imageCreate($fromImage, $fromSrc, $repo, $tag, $registry, $registryAuth);
88+
89+
$client->info();
90+
$client->version();
91+
```
92+
93+
Listing all available commands is out of scope here, please refer to the [Remote API documentation](https://docs.docker.com/reference/api/docker_remote_api_v1.15/) or the class outline.
94+
95+
Sending requests is async (non-blocking), so you can actually send multiple requests in parallel.
96+
Docker will respond to each request with a response message, the order is not guaranteed.
97+
Sending requests uses a [Promise](https://github.com/reactphp/promise)-based interface that makes it easy to react to when a request is fulfilled (i.e. either successfully resolved or rejected with an error):
98+
99+
```php
100+
$client->version()->then(
101+
function ($result) {
102+
var_dump('Result received', $result);
103+
},
104+
function (Exception $error) {
105+
var_dump('There was an error', $error->getMessage());
106+
}
107+
});
108+
```
109+
26110
## Install
27111

28112
The recommended way to install this library is [through composer](http://getcomposer.org). [New to composer?](http://getcomposer.org/doc/00-intro.md)

0 commit comments

Comments
 (0)