|
| 1 | +<?php |
| 2 | +// this simple example executes a "sleep 2" within the given running container |
| 3 | + |
| 4 | +require __DIR__ . '/../vendor/autoload.php'; |
| 5 | + |
| 6 | +use React\EventLoop\Factory as LoopFactory; |
| 7 | +use Clue\React\Docker\Factory; |
| 8 | +use Clue\React\Docker\ExecHelper; |
| 9 | +use React\Stream\Stream; |
| 10 | +use Clue\React\Buzz\Message\ResponseException; |
| 11 | + |
| 12 | +$container = isset($argv[1]) ? $argv[1] : 'asd'; |
| 13 | + |
| 14 | +$loop = LoopFactory::create(); |
| 15 | + |
| 16 | +$factory = new Factory($loop); |
| 17 | +$client = $factory->createClient(); |
| 18 | + |
| 19 | +$client->execCreate($container, array('Cmd' => array('sleep', '2'), 'AttachStdout' => true))->then(function ($info) use ($client) { |
| 20 | + echo 'Created with info: ' . json_encode($info) . PHP_EOL; |
| 21 | + |
| 22 | + return $client->execInspect($info['Id']); |
| 23 | +})->then(function ($info) use ($client) { |
| 24 | + echo 'Inspected after creation: ' . json_encode($info, JSON_PRETTY_PRINT) . PHP_EOL; |
| 25 | + |
| 26 | + return $client->execStart($info['ID'], array())->then(function ($out) use ($client, $info) { |
| 27 | + echo 'Starting returned: '; |
| 28 | + var_dump($out); |
| 29 | + |
| 30 | + return $client->execInspect($info['ID']); |
| 31 | + }); |
| 32 | +})->then(function ($info) { |
| 33 | + echo 'Inspected after execution: ' . json_encode($info, JSON_PRETTY_PRINT) . PHP_EOL; |
| 34 | +}, function (Exception $e) { |
| 35 | + echo 'ERROR: ' . $e->getMessage() . PHP_EOL; |
| 36 | + |
| 37 | + if ($e instanceof ResponseException) { |
| 38 | + echo 'Response: ' . $e->getResponse()->getBody() . PHP_EOL; |
| 39 | + } |
| 40 | +}); |
| 41 | + |
| 42 | +$loop->run(); |
0 commit comments