Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions examples/copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
use Clue\CaretNotation\Encoder;

$container = isset($argv[1]) ? $argv[1] : 'asd';
$file = isset($argv[2]) ? $argv[2] : '/etc/passwd';
echo 'Container "' . $container . '" dumping "' . $file . '" (pass as arguments to this example)' . PHP_EOL;
$path = isset($argv[2]) ? $argv[2] : '/etc/passwd';
echo 'Container "' . $container . '" dumping "' . $path . '" (pass as arguments to this example)' . PHP_EOL;

$loop = LoopFactory::create();

$factory = new Factory($loop);
$client = $factory->createClient();

$stream = $client->containerCopyStream($container, array('Resource' => $file));
$stream = $client->containerCopyStream($container, $path);

$tar = new Decoder();

Expand Down
20 changes: 12 additions & 8 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ public function containerRemove($container, $v = false, $force = false)
* Copy files or folders of container id
*
* This resolves with a string in the TAR file format containing all files
* specified in the $config array.
* specified in the given $path.
*
* Keep in mind that this means the whole string has to be kept in memory.
* For bigger containers it's usually a better idea to use a streaming approach,
Expand All @@ -547,13 +547,13 @@ public function containerRemove($container, $v = false, $force = false)
* work is clue/tar-react (see links).
*
* @param string $container container ID
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
* @param string $resource path to file or directory to copy
* @return PromiseInterface Promise<string> tar stream
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
* @link https://github.com/clue/php-tar-react library clue/tar-react
* @see self::containerCopyStream()
*/
public function containerCopy($container, $config)
public function containerCopy($container, $path)
{
return $this->postJson(
$this->uri->expand(
Expand All @@ -562,15 +562,17 @@ public function containerCopy($container, $config)
'container' => $container
)
),
$config
array(
'Resource' => $path
)
)->then(array($this->parser, 'expectPlain'));
}

/**
* Copy files or folders of container id
*
* This returns a stream in the TAR file format containing all files
* specified in the $config array.
* specified in the given $path.
*
* This works for (any number of) files of arbitrary sizes as only small chunks have to
* be kept in memory.
Expand All @@ -583,13 +585,13 @@ public function containerCopy($container, $config)
* the normal stream events.
*
* @param string $container container ID
* @param array $config resources to copy `array('Resource' => 'file.txt')` (see link)
* @param string $path path to file or directory to copy
* @return ReadableStreamInterface tar stream
* @link https://docs.docker.com/reference/api/docker_remote_api_v1.15/#copy-files-or-folders-from-a-container
* @link https://github.com/clue/php-tar-react library clue/tar-react
* @see self::containerCopy()
*/
public function containerCopyStream($container, $config)
public function containerCopyStream($container, $path)
{
return $this->streamingParser->parsePlainStream(
$this->browser->withOptions(array('streaming' => true))->post(
Expand All @@ -602,7 +604,9 @@ public function containerCopyStream($container, $config)
array(
'Content-Type' => 'application/json'
),
$this->json($config)
$this->json(array(
'Resource' => $path
))
)
);
}
Expand Down