public function testWritesRunCommands() { $contextBuilder = new ContextBuilder(); $contextBuilder->run('foo command'); $context = $contextBuilder->getContext(); $this->assertStringEqualsFile($context->getDirectory() . '/Dockerfile', <<<DOCKERFILE FROM base RUN foo command DOCKERFILE ); }
public function testExecInspect() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/daemon.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'daemon.sh')); $dockerFileBuilder->run('chmod +x /daemon.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-restart-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-restart-test', 'Cmd' => ['/daemon.sh']]); $manager->create($container); $manager->start($container); $execId = $manager->exec($container, ['/bin/bash', '-c', 'echo -n "output"']); $inspection = $manager->execinspect($execId); $this->assertEquals(0, $inspection->ExitCode); $this->assertEquals(false, $inspection->Running); }
public function testExec() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/daemon.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'daemon.sh')); $dockerFileBuilder->run('chmod +x /daemon.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-restart-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-restart-test', 'Cmd' => ['/daemon.sh']]); $manager->create($container); $manager->start($container); $type = 0; $output = ""; $execId = $manager->exec($container, ['/bin/bash', '-c', 'echo -n "output"']); $this->assertNotNull($execId); $response = $manager->execstart($execId, function ($log, $stdtype) use(&$type, &$output) { $type = $stdtype; $output = $log; }); $response->getBody()->getContents(); $manager->kill($container); $this->assertEquals(1, $type); $this->assertEquals('output', $output); }
public function testKill() { $manager = $this->getManager(); $dockerFileBuilder = new ContextBuilder(); $dockerFileBuilder->from('ubuntu:precise'); $dockerFileBuilder->add('/kill.sh', file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'script' . DIRECTORY_SEPARATOR . 'kill.sh')); $dockerFileBuilder->run('chmod +x /kill.sh'); $this->getDocker()->build($dockerFileBuilder->getContext(), 'docker-php-kill-test', null, true, false, true); $container = new Container(['Image' => 'docker-php-kill-test', 'Cmd' => ['/kill.sh']]); $manager->create($container); $manager->start($container); $manager->kill($container, "SIGHUP"); $logs = $manager->logs($container, false, true); $logs = array_map(function ($value) { return $value['output']; }, $logs); $manager->stop($container); $manager->remove($container); $this->getDocker()->getImageManager()->delete($container->getImage()); $this->assertContains('HUP', implode("", $logs)); }