Skip to content

Commit 24578f4

Browse files
committed
Add containerExport(), containerCopy() and containerChanges() methods
1 parent 9cd1ad4 commit 24578f4

2 files changed

Lines changed: 61 additions & 0 deletions

File tree

src/Client.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ public function containerTop($container)
125125
return $this->browser->get($this->url('/containers/%s/top', $container))->then(array($this->parser, 'expectJson'));
126126
}
127127

128+
/**
129+
* Inspect changes on container id's filesystem
130+
*
131+
* @param string $container container ID
132+
* @return Promise Promise<array>
133+
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#inspect-changes-on-a-containers-filesystem
134+
*/
135+
public function containerChanges($container)
136+
{
137+
return $this->browser->get($this->url('/containers/%s/changes', $container))->then(array($this->parser, 'expectJson'));
138+
}
139+
140+
/**
141+
* Export the contents of container id
142+
*
143+
* @param string $container container ID
144+
* @return Promise Promise<string> tar stream
145+
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#export-a-container
146+
*/
147+
public function containerExport($container)
148+
{
149+
return $this->browser->get($this->url('/containers/%s/export', $container))->then(array($this->parser, 'expectPlain'));
150+
}
151+
128152
/**
129153
* Resize the TTY of container id
130154
*
@@ -241,6 +265,18 @@ public function containerRemove($container, $v = false, $force = false)
241265
return $this->browser->delete($this->url('/containers/%s?v=%u&force=%u', $container, $v, $force))->then(array($this->parser, 'expectEmpty'));
242266
}
243267

268+
/**
269+
* Copy files or folders of container id
270+
*
271+
* @param string $container container ID
272+
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
273+
* @return Promise Promise<string> tar stream
274+
*/
275+
public function containerCopy($container, $config)
276+
{
277+
return $this->postJson($this->url('/containers/%s/copy', $container), $config)->then(array($this->parser, 'expectPlain'));
278+
}
279+
244280
/**
245281
* Sets up an exec instance in a running container id
246282
*

tests/ClientTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,22 @@ public function testContainerTop()
6060
$this->expectPromiseResolveWith($json, $this->client->containerTop(123));
6161
}
6262

63+
public function testContainerChanges()
64+
{
65+
$json = array();
66+
$this->expectRequestFlow('get', '/containers/123/changes', $this->createResponseJson($json), 'expectJson');
67+
68+
$this->expectPromiseResolveWith($json, $this->client->containerChanges(123));
69+
}
70+
71+
public function testContainerExport()
72+
{
73+
$data = 'tar stream';
74+
$this->expectRequestFlow('get', '/containers/123/export', $this->createResponse($data), 'expectPlain');
75+
76+
$this->expectPromiseResolveWith($data, $this->client->containerExport(123));
77+
}
78+
6379
public function testContainerWait()
6480
{
6581
$json = array();
@@ -139,6 +155,15 @@ public function testContainerResize()
139155
$this->expectPromiseResolveWith('', $this->client->containerResize(123, 800, 600));
140156
}
141157

158+
public function testContainerCopy()
159+
{
160+
$data = 'tar stream';
161+
$config = array('Resource' => 'file.txt');
162+
$this->expectRequestFlow('post', '/containers/123/copy', $this->createResponse($data), 'expectPlain');
163+
164+
$this->expectPromiseResolveWith($data, $this->client->containerCopy('123', $config));
165+
}
166+
142167
public function testExecCreate()
143168
{
144169
$json = array();

0 commit comments

Comments
 (0)