jarkt/docker-php-client 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jarkt/docker-php-client

Composer 安装命令:

composer require jarkt/docker-php-client

包简介

README 文档

README

Installation

Install via composer:

{
	"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.

First create an instance of the ApiClient.

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

Example:

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

(Haha, like 1.21 Gigawatt :-)

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:

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.

Here are some examples:

$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.

Here are some examples:

$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.

Developers

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

Update dependencies with: ./update.sh

Run the tests with: ./test.sh

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

统计信息

  • 总下载量: 1.86k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 7
  • Watchers: 2
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2016-02-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固