-
-
Save jottr/af12751f166ab5995f09 to your computer and use it in GitHub Desktop.
SilverstripeLauncher.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Docker; | |
require '../vendor/autoload.php'; | |
use Docker\Context\Context; | |
use Docker\Http\Client; | |
use Docker\Manager\ContainerManager; | |
use Docker\Manager\ImageManager; | |
use Docker\Exception\UnexpectedStatusCodeException; | |
class SilverstripeLauncher extends Docker | |
{ | |
private $client; | |
private $manager; | |
private $container; | |
private $name; | |
private $ip; | |
public function __construct(Client $client = null) | |
{ | |
$this->client = $client ?: new Client('tcp://127.0.0.1:4243'); | |
$this->manager = new ContainerManager($this->client); | |
if ($this->client===null){ | |
throw new Exception("Could not create a new Client"); | |
} | |
if ($this->manager===null){ | |
throw new Exception("Could not create a ContainerManager."); | |
} | |
else { | |
$headers = $this->client->getDefaultHeaders(); | |
} | |
} | |
public function getContainerIP($name) | |
{ | |
$this->name = $name; | |
try | |
{ | |
$this->container = $this->manager->find($name); | |
if ($this->container===null){ | |
throw new Exception("Could not find a Container with name: $name \n"); | |
} | |
} | |
catch (Exception $e) | |
{ | |
echo $e->getMessage(); | |
} | |
try | |
{ | |
$this->ip = $this->container->getRuntimeInformations()['NetworkSettings']['IPAddress']; | |
if ($this->ip===null){ | |
throw new Exception("Could not get Runtime Information of container with the name: $name." ); | |
} | |
} | |
catch (Exception $e) | |
{ | |
echo $e->getMessage(); | |
} | |
return $this->ip; | |
} | |
} | |
$ssl = new SilverstripeLauncher; | |
$ip = $ssl->getContainerIP("mysql"); | |
echo $ip; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment