2017 © Pedro Peláez
 

library docker-php-client

image

jarkt/docker-php-client

  • Wednesday, June 13, 2018
  • by jarkt
  • Repository
  • 1 Watchers
  • 4 Stars
  • 1,058 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 12 Versions
  • 10 % Grown

The README.md

Usage

Installation

Install via composer:, (*1)

{
    "require": {
        "jarkt/docker-php-client": "1.0.*"
    }
}

Usage

The ApiClient connects to the Docker Remote API via HTTP. You can use the container "jarkt/docker-remote-api" to make the API available., (*2)

First create an instance of the ApiClient., (*3)

\jarkt\docker\ApiClient::construct ($host, $port [, $version ] )

Example:, (*4)

$docker = new ApiClient(getenv('API_PORT_2375_TCP_ADDR'), getenv('API_PORT_2375_TCP_PORT'), 'v1.21');

(Haha, like 1.21 Gigawatt :-), (*5)

You can use various types of request methods to perform your API call. There are get, head, delete, post and put. The signatures are the same:, (*6)

method ($path [, array $params [, requestHandlers\RequestHandler $requestHandler ]] )

For your call you have to serve the request path and optional an array of request parameters. Some requests require data in the request body - for these you can also give an instance of an implementation of a requestHandlers\RequestHandler. These implementation prepares a certain data type for the http api request., (*7)

Here are some examples:, (*8)

$response = $docker->get('/containers/json');
$response = $docker->head('/containers/4fa6e0f0c678/archive', ['path' => '/path/on/container']);
$response = $docker->post('/containers/create', [], new requestHandlers\Json(['Image' => '4fa6e0f0c678']));
$response = $docker->put(
    '/containers/4fa6e0f0c678/archive',
    ['path' => '/path/on/container'],
    new requestHandlers\Files('/path/on/local/machine')
);

From the response you can get the status code, to decide what type of ResponseHandler you need. Use a responseHandler\ResponseHandler to get informations from the response or to start actions on the local machine like unpacking a tar archive., (*9)

Here are some examples:, (*10)

$response = $docker->get('/containers/json');
if($response->getStatus() === 200) {
    $responseHandler = new responseHandlers\Json($response);
    $containers = $responseHandler->getData();
    var_dump($containers);
}
$response = $docker->get('/containers/4fa6e0f0c678/archive', ['path' => '/path/on/container']);
if($response->getStatus() === 200) {
    $responseHandler = new responseHandlers\Files($response);
    $stat = json_decode(base64_decode($responseHandler->getHeader('x-docker-container-path-stat')), true);
    var_dump($stat);
    $responseHandler->extract('/path/on/local/machine');
}

Hint

Use the environment variable HOSTNAME as the container id of your own host., (*11)

Developers

Tests are running inside a docker container. Install all the test dependencies by going to the "containers" folder and type: ./install.sh, (*12)

Update dependencies with: ./update.sh, (*13)

Run the tests with: ./test.sh, (*14)

This will make the API available through the container "jarkt/docker-remote-api" and run the tests against this endpoint., (*15)

The Versions

13/06 2018

dev-master

9999999-dev

  Sources   Download

The Development Requires

13/06 2018

1.0.4

1.0.4.0

  Sources   Download

The Development Requires

13/06 2018

1.0.5

1.0.5.0

  Sources   Download

The Development Requires

12/06 2018

1.0.3

1.0.3.0

  Sources   Download

The Development Requires

07/06 2018

1.0.2

1.0.2.0

  Sources   Download

The Development Requires

03/12 2017

1.0.1

1.0.1.0

  Sources   Download

The Development Requires

23/11 2017

1.0.0

1.0.0.0

  Sources   Download

The Development Requires

13/05 2016

0.9.4

0.9.4.0

  Sources   Download

The Development Requires

21/04 2016

0.9.3

0.9.3.0

  Sources   Download

The Development Requires

16/02 2016

0.9.2

0.9.2.0

  Sources   Download

The Development Requires

16/02 2016

0.9.1

0.9.1.0

  Sources   Download

The Development Requires

08/02 2016

0.9.0

0.9.0.0

  Sources   Download

The Development Requires