Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jottr
Created January 15, 2014 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jottr/af12751f166ab5995f09 to your computer and use it in GitHub Desktop.
Save jottr/af12751f166ab5995f09 to your computer and use it in GitHub Desktop.
SilverstripeLauncher.php
<?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