File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+ // this example shows how the containerExport() call returns a TAR stream
3+ // and how we it can be piped into a output tar file.
4+
5+ require __DIR__ . '/../vendor/autoload.php ' ;
6+
7+ use React \EventLoop \StreamSelectLoop ;
8+ use Clue \React \Docker \Factory ;
9+ use React \Stream \Stream ;
10+
11+ $ container = isset ($ argv [1 ]) ? $ argv [1 ] : 'asd ' ;
12+ $ target = isset ($ argv [2 ]) ? $ argv [2 ] : ($ container . '.tar ' );
13+ echo 'Exporting whole container " ' . $ container . '" to " ' . $ target .'" (pass as arguments to this example) ' . PHP_EOL ;
14+
15+ $ loop = new StreamSelectLoop ();
16+
17+ $ factory = new Factory ($ loop );
18+ $ client = $ factory ->createClient ();
19+
20+ $ stream = $ client ->containerExportStream ($ container );
21+
22+ $ stream ->on ('error ' , function ($ e = null ) {
23+ // will be called if the container is invalid/does not exist
24+ echo 'ERROR requesting stream ' . PHP_EOL . $ e ;
25+ });
26+
27+ $ out = new Stream (fopen ($ target , 'w ' ), $ loop );
28+ $ stream ->pipe ($ out );
29+
30+ $ loop ->run ();
You can’t perform that action at this time.
0 commit comments