-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.php
More file actions
87 lines (64 loc) · 2.05 KB
/
Test.php
File metadata and controls
87 lines (64 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<?php
use DockerClient\Transporters\Container;
use DockerClient\Configs\ContainerConfig;
use DockerClient\Entities\ContainerEntity;
use DockerClient\Transporters\Image;
use DockerClient\Configs\ImageConfig;
require "vendor/autoload.php";
$testContainerName = str_random(10);
$testImageName = strtolower(str_random(10));
switch ($argv[1]) {
// List all containers
case 'ls':
dd(Container::ls());
break;
// Create and start a new container
case 'create':
$containerConfig = new ContainerConfig($testContainerName, [
'Image' => 'nginx'
]);
$container = new Container();
$container->create($containerConfig);
// Start
$container->start();
echo $container->getEntity()->getEntityID();
break;
case 'build':
$image = new Image();
$imageConfig = new ImageConfig('compressWithDockerfile.tar.bz2', [
't' => $testImageName
]);
$image->build($imageConfig);
$container = new Container();
$containerConfig = new ContainerConfig(
$containerName = $testContainerName,
$configs = [
'Image' => $image->getEntity()
]
);
$container->create($containerConfig);
$container->start();
echo $container->getEntity()->getEntityID();
break;
// Start a stopped container
case 'start':
if (!isset($argv[2])){
die("Please provide a containerID or containerName to start! \n");
}
$containerEntity = new ContainerEntity($argv[2]);
$containerEntity->start();
echo $containerEntity->getEntityID();
break;
// Stop a container
case 'stop':
if (!isset($argv[2])){
die("Please provide a containerID or containerName to stop! \n");
}
$containerEntity = new ContainerEntity($argv[2]);
$containerEntity->stop();
echo $containerEntity->getEntityID();
break;
case 'test':
fwrite(STDOUT, "OK");
break;
}